File tree Expand file tree Collapse file tree 4 files changed +64
-0
lines changed Expand file tree Collapse file tree 4 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ # create an address label format
2+
3+ # modules
4+ import sys
5+
6+ # params
7+ str_salutation = "Mr and Mrs"
8+
9+ # get user input - NO validation
10+
11+ str_name = input ( "Please enter your last name" )
12+
13+ var_house_number = input ( "Please enter your house number" )
14+ if var_house_number .isdigit ():
15+ int_house_number = int ( var_house_number )
16+ else :
17+ sys .exit ("Invalid house number " )
18+
19+ str_road = input ( "Please enter your road name" )
20+ str_town = input ( "Please enter your town" )
21+
22+ print ( "Address Label Creator" )
23+ print ( "-" * 22 )
24+ print ( f'{ str_salutation } { str_name } ' )
25+ print ( f'{ str (int_house_number )} { str_road } ' )
26+ print ( f'{ str_town } ' )
Original file line number Diff line number Diff line change 1+ # Play around with a users age
2+
3+ # import modules
4+ import sys
5+
6+ # Params
7+ f_valid = 0
8+
9+ # Display header
10+ print ( "Welcome to the Age Adjustor " )
11+ print ( "-" * 40 )
12+
13+ # Get user input and validate
14+ while f_valid != 1 :
15+ var_age = ( input ( f"Please enter your age: " ) )
16+
17+ # Allow a way out by entering an empty string to quit
18+ if var_age == "" :
19+ sys .exit ( "Empty value detected - quitting." )
20+
21+ try :
22+ int_age = int ( var_age )
23+ f_valid = 1
24+ except ValueError :
25+ print ( f"Invalid value entered, ({ var_age } ). Please try again." )
26+ except :
27+ print ( "+++ Out of cheese error +++" )
28+
29+ # Calc the dates
30+ int_last_year = int_age - 1
31+ int_next_year = int_age + 1
32+
33+ # output the results
34+
35+ print ( "-" * 40 )
36+ print ( f"Your current age is " + str (int_age ) )
37+ print ( f"Before your last birthday you were " + str (int_last_year ) )
38+ print ( f"After your next birthday you will be " + str (int_next_year ) )
You can’t perform that action at this time.
0 commit comments