Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions source/week-1/conditions/multilpe-conditions/or_statements.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
province = input("What province do you live in? ")
tax = 0
if province == 'Alberta' \
or province == 'Nunavut':
tax = 0.05
elif province == 'Ontario':
tax = 0.13
if province == "Alberta" or province == "Nunavut":
tax = 0.05
elif province == "Ontario":
tax = 0.13
else:
tax = 0.15
tax = 0.15
print(tax)
2 changes: 1 addition & 1 deletion source/week-1/conditions/single/code_challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
if price > 1.00:
tax = .07
print('Tax rate is: ' + str(tax))
else
else:
tax = 0
print('Tax rate is: ' + str(tax))
7 changes: 6 additions & 1 deletion source/week-1/dates/format_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
# to display only part of the date
# All these functions return integers
# Convert them to strings before concatenating them to another string
print('Day: ' + str(today.day))
print('Date: ' + str(today.day))
print('Month: ' + str(today.month))
print('Year: ' + str(today.year))

print('Hour: ' + str(today.hour))
print('Minute: ' + str(today.minute))
print('Second: ' + str(today.second))

# Using the strftime() Method
print("DD/MM/YY: " + str(today.strftime('%d/%m/%y')))
print("DD Month YYYY: " + str(today.strftime('%d %B %Y')))
print("MM/DD/YYYY, H:M:S : " + str(today.strftime("%m/%d/%Y, %H:%M:%S")))
24 changes: 17 additions & 7 deletions source/week-1/error-handling/runtime.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
x = 42
y = 0
# Error Handling
try:
print(x / y)
except ZeroDivisionError as e:
# Optionally, log e somewhere
print('Sorry, something went wrong')
print(x)
except NameError:
print("Variable x is not defined")
except:
print('Something really went wrong')
print("Something else went wrong")
finally:
print('This always runs on success or failure')

# Use while to create an infinite loop that will run
# # until false is returned (correct input in this case)
while True:
try:
x = int(input("Please enter a number: "))
break
except ValueError:
print("Oops! That was no valid number. Try again...")

# Instead of letting python to shout at the user "ValueError"
# we catch the anticipated error and display a polite message
4 changes: 2 additions & 2 deletions source/week-1/error-handling/syntax.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
x = 42
y = 206
if x == y
print('Success')
if x == y:
print("Success")
12 changes: 12 additions & 0 deletions source/week-1/variables/string-variables/f_strings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Only available for python 3.6+
# This new way of formatting strings lets you
# use embedded Python expressions inside string constants.

name = input("What is your name? ")
subject = input("What subject do you like? ")
print(f"{name}'s favorite subject is {subject}.")

a = 5
b = 10
sum = a + b
print(f'{a} plus {b} is equal to {sum}.')