Skip to content

Commit e49cbdf

Browse files
committed
Commit 4
1 parent 550c36b commit e49cbdf

File tree

12 files changed

+69
-11
lines changed

12 files changed

+69
-11
lines changed

python-for-beginners/03 - Comments/enable_pin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# we cover methods in a separate module
66
def enable_pin(user, pin):
77
print('pin enabled')
8+
print(user + " " + pin)
89

910
# Set current_user and pin to test values
1011
current_user = 'TEST123'

python-for-beginners/04 - String variables/code_challenge.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
# Make sure you have a space between first and last name
55
# Make sure the first letter of first name and last name is uppercase
66
# Make sure the rest of the name is lowercase
7+
firstName = input("Fist name please?")
8+
lastName = input("Last name please?")
9+
print(firstName.capitalize()+" "+lastName.capitalize())

python-for-beginners/04 - String variables/format_strings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
# the first letter uppercase and the rest of the word lowercase
77
print ('Hello ' + first_name.capitalize() + ' ' \
88
+ last_name.capitalize())
9+
10+
11+
print(f"Hola {input('First name?')} {input('Last name?')}")

python-for-beginners/05 - Numeric variables/code_challenge.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
# Print 'first number + second number = answer'
55
# For example if someone enters 4 and 6 the output should read
66
# 4 + 6 = 10
7+
number1 = input('Number 1 ')
8+
number2 = input('Number 2 ')
9+
print(f'{number1} + {number2} = {str(int(number2)+int(number1))}')

python-for-beginners/05 - Numeric variables/combining_strings_and_numbers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# The + operator can either add two numbers or it can concatenate two strings
77
# it does not know what to do when you pass it one number and one string
88
# This line of code will cause an error
9-
print(days_in_feb + ' days in February')
9+
#print(days_in_feb + ' days in February')
1010

1111
# You need to convert the number to a string to display the value
1212
# This line of code will work
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
# print today's date
22
# print yesterday's date
33
# ask a user to enter a date
4-
# print the date one week from the date entered
4+
# print the date one week from the date entered
5+
from datetime import datetime, timedelta
6+
7+
currentdate = datetime.now()
8+
9+
print(str(currentdate - timedelta(days=1)))
10+
print(str(currentdate + timedelta(weeks=1)))
11+
12+
print(f"{currentdate:%d/%m/%Y}")
13+
print('{:%d - %m - %Y}'.format(currentdate))

python-for-beginners/06 - Dates/code_challenge_solution.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616
# print the date one week from the date entered
1717
one_week = timedelta(weeks=1)
1818
one_week_later = date_entered + one_week
19-
print('One week later it will be: ' + str(one_week_later))
19+
print('One week later it will be: ' + str(one_week_later))
20+
21+

python-for-beginners/08 - Handling conditions/code_challenge.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
# If I enter 0.50 I should see the message "Tax rate is: 0"
55
price = input('how much did you pay? ')
66

7-
if price > 1.00:
7+
if float(price) >= 1.00:
88
tax = .07
9-
print('Tax rate is: ' + str(tax))
10-
else
9+
else:
1110
tax = 0
1211
print('Tax rate is: ' + str(tax))

python-for-beginners/09 - Handling multiple conditions/code_challenge.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,18 @@
1111
# Bob should be in room AB
1212
# Charlie should be in room C
1313
# Khalid Haque should be in room OTHER
14-
# Xin Zhao should be in room Z
14+
# Xin Zhao should be in room Z
15+
name = input('What is your name? ')
16+
17+
if name.capitalize().startswith('A') or name.capitalize().startswith('B'):
18+
print('Go to room AB')
19+
elif name.capitalize().startswith('C'):
20+
print('Go to room CD')
21+
else:
22+
lastName = input('What is your last name? ')
23+
if lastName.capitalize().startswith('Z'):
24+
print('Go to room Z')
25+
else:
26+
print('Go to room OTHER')
27+
28+

python-for-beginners/09 - Handling multiple conditions/multiple_if_statements.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
if province == 'Alberta':
66
tax = 0.05
7-
if province == 'Nunavut':
7+
elif province == 'Nunavut':
88
tax = 0.05
9-
if province == 'Ontario':
9+
elif province == 'Ontario':
1010
tax = 0.13
11+
else:
12+
tax = .15
1113
print(tax)

python-for-beginners/10 - Complex conditon checks/boolean_variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
# Somewhere later in your code if you need to check if students is
1212
# on honour roll, all I need to do is check the boolean variable
1313
# I set earlier in my code
14-
if honour_roll:
14+
if not honour_roll:
1515
print('You made honour roll')

python-for-beginners/10 - Complex conditon checks/code_challenge.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,26 @@
2121
# first name: ReallyLongFirstName last name: Ibach
2222
# output: R. Ibach
2323
# first name: ReallyLongFirstName last name: ReallyLongLastName
24-
# output: ReallyLongLastName
24+
# output: ReallyLongLastName
25+
26+
name = input('What is your name? ')
27+
lastName = input('What is your last name? ')
28+
29+
30+
if len(name)<10:
31+
nameLessTen = True
32+
else:
33+
nameLessTen = False
34+
35+
if len(lastName)<10:
36+
lastNameLessTen = True
37+
else:
38+
lastNameLessTen = False
39+
40+
if nameLessTen and lastNameLessTen:
41+
print(name + ' ' + lastName)
42+
elif not nameLessTen and lastNameLessTen < 10:
43+
print(name[0:1] + '. '+lastName)
44+
elif nameLessTen and not lastNameLessTen:
45+
print(name + ' '+lastName[0:1]+'.')
46+
else: print(lastName)

0 commit comments

Comments
 (0)