File tree 12 files changed +69
-11
lines changed
09 - Handling multiple conditions
10 - Complex conditon checks 12 files changed +69
-11
lines changed Original file line number Diff line number Diff line change 5
5
# we cover methods in a separate module
6
6
def enable_pin (user , pin ):
7
7
print ('pin enabled' )
8
+ print (user + " " + pin )
8
9
9
10
# Set current_user and pin to test values
10
11
current_user = 'TEST123'
Original file line number Diff line number Diff line change 4
4
# Make sure you have a space between first and last name
5
5
# Make sure the first letter of first name and last name is uppercase
6
6
# 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 ())
Original file line number Diff line number Diff line change 6
6
# the first letter uppercase and the rest of the word lowercase
7
7
print ('Hello ' + first_name .capitalize () + ' ' \
8
8
+ last_name .capitalize ())
9
+
10
+
11
+ print (f"Hola { input ('First name?' )} { input ('Last name?' )} " )
Original file line number Diff line number Diff line change 4
4
# Print 'first number + second number = answer'
5
5
# For example if someone enters 4 and 6 the output should read
6
6
# 4 + 6 = 10
7
+ number1 = input ('Number 1 ' )
8
+ number2 = input ('Number 2 ' )
9
+ print (f'{ number1 } + { number2 } = { str (int (number2 )+ int (number1 ))} ' )
Original file line number Diff line number Diff line change 6
6
# The + operator can either add two numbers or it can concatenate two strings
7
7
# it does not know what to do when you pass it one number and one string
8
8
# This line of code will cause an error
9
- print (days_in_feb + ' days in February' )
9
+ # print(days_in_feb + ' days in February')
10
10
11
11
# You need to convert the number to a string to display the value
12
12
# This line of code will work
Original file line number Diff line number Diff line change 1
1
# print today's date
2
2
# print yesterday's date
3
3
# 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 ))
Original file line number Diff line number Diff line change 16
16
# print the date one week from the date entered
17
17
one_week = timedelta (weeks = 1 )
18
18
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
+
Original file line number Diff line number Diff line change 4
4
# If I enter 0.50 I should see the message "Tax rate is: 0"
5
5
price = input ('how much did you pay? ' )
6
6
7
- if price > 1.00 :
7
+ if float ( price ) >= 1.00 :
8
8
tax = .07
9
- print ('Tax rate is: ' + str (tax ))
10
- else
9
+ else :
11
10
tax = 0
12
11
print ('Tax rate is: ' + str (tax ))
Original file line number Diff line number Diff line change 11
11
# Bob should be in room AB
12
12
# Charlie should be in room C
13
13
# 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
+
Original file line number Diff line number Diff line change 4
4
5
5
if province == 'Alberta' :
6
6
tax = 0.05
7
- if province == 'Nunavut' :
7
+ elif province == 'Nunavut' :
8
8
tax = 0.05
9
- if province == 'Ontario' :
9
+ elif province == 'Ontario' :
10
10
tax = 0.13
11
+ else :
12
+ tax = .15
11
13
print (tax )
Original file line number Diff line number Diff line change 11
11
# Somewhere later in your code if you need to check if students is
12
12
# on honour roll, all I need to do is check the boolean variable
13
13
# I set earlier in my code
14
- if honour_roll :
14
+ if not honour_roll :
15
15
print ('You made honour roll' )
Original file line number Diff line number Diff line change 21
21
# first name: ReallyLongFirstName last name: Ibach
22
22
# output: R. Ibach
23
23
# 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 )
You can’t perform that action at this time.
0 commit comments