Skip to content
Snippets Groups Projects
Commit 656c345c authored by Sam Rose's avatar Sam Rose
Browse files

Replace broken iPython Notebook file example

parent 9b3e9287
No related branches found
No related tags found
1 merge request!2Resolve "Replace iPython Notebook file example"
from tutor import check
print('Hello, World!')
# This is a comment, it isn't run as code, but often they are helpful
1 + 1
8 + 6*2*3 - (15 - 13)
42 + 3.149 + -1
meal = 200.00
# as a decimal, 10% would be 0.1
tip_percent = 0.10
meal * tip_percent
meal = 200.00
# as integer, 10% would be 10
tip_percent = 10
meal * tip_percent / 100
meal = 200.00
print(meal)
meal = "Hello, World!"
print(meal)
gibberish
*adsflf_
print('Hello'
1v34
2000 / 0
print('Hello, World!)
aswer = 3 * 8
print(answer)
"Hello, World!"
your_name = "Albert O'Connor"
print("Hello, ")
print(your_name)
dir("Hello, World!")
string = "Hello, World"
string.upper()
string = "Hello, World"
string.lower()
"Hello, World".upper()
your_name = "Albert O'Connor"
string = "Hello, {0}!"
print(string.format(your_name))
print("Hello, {0}!".format("Albert O'Connor"))
"{0} likes {1}".format("Albert O'Connor", 'Python')
print("200 University Ave. Waterloo, ON")
# Edit this string
template ="{0} {1} {2} {3}"
# Leave this alone please, it will help you as you go through the exercise
check('p1', template.format("alice@domain.org", "bob@domain.org", "Alice's Subject", "This is my one line message!"))
False is False
True is True
True is False
true is False
1 > 2
"Cool".startswith("C")
"Cool".endswith("C")
"oo" in "Cool"
42 == 1 # note the double equals sign for equality
condition = 1 > 2
if condition:
print("Condition is True")
else:
print("Condition is False")
condition = True
if condition:
print("Condition is True")
else:
print("Condition is False")
print("Condition is True or False, either way this is outputted")
# Edit the values of these 3 variables
boolean_literal = False
number = 8
string_literal = "I like to count sheep before bed."
# Leave this code the same please
if number > 10 and boolean_literal and "cows" in string_literal:
print("Success!")
else:
print("Try again!")
# This just provides some hints
check("p3", (number, boolean_literal, string_literal))
# The empty list
[]
["Milk", "Eggs", "Bacon"]
[1,2,3]
[True, 0, "Awesome"]
your_name = "Albert O'Connor"
awesome_people = ["Eric Idle", your_name]
print(awesome_people)
dir([])
your_name = "Albert O'Connor"
awesome_people = ["Eric Idle", your_name]
awesome_people.append("John Cleese")
print(awesome_people)
awesome_people[0]
print("These people are awesome: {0}, {1}, {2}".format(awesome_people[0], awesome_people[1], awesome_people[2]))
your_name = "Albert O'Connor"
awesome_people = ["Eric Idle", your_name]
awesome_people.append("John Cleese")
for person in awesome_people:
print(person)
person = awesome_people[0]
print(person)
person = awesome_people[1]
print(person)
person = awesome_people[2]
print(person)
range(0,10)
for number in range(0,10):
print("{0} squared is {1}".format(number, number*number))
# Edit the contents of this list
number_list = []
# Leave this line alone please
check("p4", number_list)
{"Python": "An awesome programming language",
"Monty Python": "A british comedy troupe"}
our_dictionary = {
"Python": "An awesome programming language",
"Monty Python": "A british comedy troupe"
}
our_dictionary["Python"]
for key in our_dictionary:
print('The Key is "{0}" and the value is "{1}"'.format(key, our_dictionary[key]))
print('Hello, {name}! Your favorite color is {favorite_color}.'.format(name="Albert O'Connor",
favorite_color='green'))
info = {'name': "Albert O'Connor",
'favorite color': 'green'}
print('Hello, {name}! Your favorite color is {favorite color}.'.format(**info))
data = {'name': "Albert O'Connor",
'favorite_color': 'green'}
print('{0}'.format(data)) # This prints the dictionary as text
data = {'name': "Albert O'Connor",
'favorite_color': 'green'}
print('{0}'.format(**data)) # This produces an error, there are no indexable arguments, just keyword
data = {'name': "Albert O'Connor",
'favorite_color': 'green'}
print('{0}'.format('Eric!', **data)) # Eric is the 0th argument, all the keywords are ignored!
data = {'name': "Albert O'Connor",
'favorite_color': 'green'}
# data is passed as indexiable so there is no keyword arguments.
print('Hello, {name}! Your favorite color is {favorite_color}.'.format(data))
data = {'name': "Albert O'Connor",
'favorite_color': 'green'}
# There we go, name and favorite_color are passed as keywords.
print('Hello, {name}! Your favorite color is {favorite_color}.'.format(**data))
data = {'name': "Albert O'Connor",
'favorite_color': 'green'}
# data is passed as keyword, but doesn't have the key 'pet_name'.
print('{pet_name}'.format(**data))
# Edit with the values you want.
entry_1 = {'name': "",
'email': ""}
# Add the keys and values to this entry like above.
entry_2 = {}
print(entry_1)
print(entry_2)
entries = [entry_1,] # Edit this list to include both entries
print(entries)
# Edit this message
message = """To: {email}
Hey you,
How is the weather?
"""
print message
for entry in entries:
print(message) # Add .format with the right arguments
print("-"*40)
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment