File tree Expand file tree Collapse file tree 5 files changed +184
-0
lines changed Expand file tree Collapse file tree 5 files changed +184
-0
lines changed Original file line number Diff line number Diff line change 1+ # Calculate cuboid stats
2+
3+ # helpers
4+
5+ ## function to get an integer with error checking
6+ def get_int (input_prompt , min_val = int (1 ), max_val = int (100 )):
7+ return_value = int (0 )
8+ int_val = int (- 1 )
9+
10+ try :
11+ while not ((int_val >= min_int & int_val <= max_val )) :
12+ get_val = input (input_prompt + f" (Min: { str (min_int )} Max: { str (max_int )} Exit: 0)" )
13+ int_val = int (get_val )
14+
15+ ## exit if select 0
16+ if int_val == 0 :
17+ break
18+
19+ return_value = int_val
20+ except :
21+ print ( f"Invalid '{ input_prompt } ' value entered '" + get_val + "'" )
22+ finally :
23+ return return_value
24+
25+
26+
27+ # params
28+ min_int = int (1 )
29+ max_int = int (100 )
30+
31+ print ( 'Welcome to the Cuboid Calculator' )
32+ print ( '-' * 40 )
33+
34+ cub_width = get_int ("Width (cm): " )
35+ cub_height = get_int ("Height (cm): " )
36+ cub_length = get_int ("Length (cm): " )
37+
38+ print (type (cub_width ))
39+ print (type (cub_height ))
40+ print (type (cub_length ))
41+
42+
43+ if ( cub_width > int (0 ) and cub_height > int (0 ) and cub_length > int (0 ) ) :
44+ surface = 2 * ( ( cub_width * cub_height ) + ( cub_height * cub_length ) + ( cub_length * cub_width ) )
45+ volume = cub_height * cub_length * cub_width
46+
47+ print ( f'Width: { cub_width } Height: { cub_height } Length: { cub_length } ' )
48+ print ( f'Surface area: { str (surface )} Volume: { str (volume )} ' )
49+
50+
51+ else :
52+
53+ print ( f'Width: { cub_width } Height: { cub_height } Length: { cub_length } ' )
54+ print ("Invalid dimensions provided. Cannot calculate answers." )
55+
56+
57+
Original file line number Diff line number Diff line change 1+ variable = str (1234546 )
2+ var2 = float (variable )
3+ print (var2 )
Original file line number Diff line number Diff line change 1+ # swap the value of 2 variables.
2+
3+ # inits
4+ x = 50
5+ y = 60
6+
7+ # display the start
8+ print (f'Start : x={ x } y={ y } ' )
9+
10+ # switch a roo
11+ tempZ = x
12+ x = y
13+ y = tempZ
14+
15+ # display the magic
16+ print (f'End : x={ x } y={ y } ' )
17+
Original file line number Diff line number Diff line change 1+ ## Calculate an employees salary
2+
3+ ## inits
4+ sal_lecturer = int (50000 )
5+ sal_lecturer_allowance = int (10000 )
6+ sal_lecturer_ot = int (0 )
7+ sal_clerk = int (30000 )
8+ sal_clerk_ot = int (20 )
9+ sal_clerk_allowance = int (0 )
10+
11+ # header
12+ print (f'Welcome to the Salary Sum System 2000' )
13+ print ('-' * 50 )
14+
15+ # Get params from user
16+ print ("Please enter staff name" )
17+ staff_name = input ("Enter Name :" )
18+ print ("Please enter staff type. L for Lecturer, C for Clerk" )
19+ staff_type = input ("Type (L or C) :" )
20+ ot_hours = int (0 )
21+ salary = int (0 )
22+
23+ if staff_type .upper ()== "L" :
24+ base_salary = sal_lecturer
25+ ot_rate = sal_lecturer_ot
26+ allowance = sal_lecturer_allowance
27+ staff_label = "Lecturer"
28+
29+ elif staff_type .upper ()== "C" :
30+ ot_hours = int (input ("Please enter OT hours: " ))
31+ base_salary = sal_clerk
32+ ot_rate = sal_clerk_ot
33+ allowance = sal_clerk_allowance
34+ staff_label = "Clerk"
35+
36+ else :
37+ staff_label = "Unknown"
38+ base_salary = int (0 )
39+ ot_rate = int (0 )
40+ allowance = int (0 )
41+ ot_hours = int (0 )
42+
43+ salary = base_salary
44+ salary += (ot_hours * ot_rate )
45+ salary += allowance
46+
47+ # Output result
48+ print (f'{ staff_name } is a { staff_label } ' )
49+ print (f' Base Salary : £{ base_salary :8} ' )
50+ print (f' OT Hours : £{ ot_hours :8} ' )
51+ print (f' OT Rate : £{ ot_rate :8} ' )
52+ print (f' Allowance : £{ allowance :8} ' )
53+ print (f' Total Salary: £{ salary :8} ' )
Original file line number Diff line number Diff line change 1+ ## Calculate an employees salary
2+
3+ ## inits
4+ sal_lecturer = int (50000 )
5+ sal_lecturer_allowance = int (10000 )
6+ sal_lecturer_ot = int (0 )
7+ sal_clerk = int (30000 )
8+ sal_clerk_ot = int (20 )
9+ sal_clerk_allowance = int (0 )
10+
11+ # header
12+ print (f'Welcome to the Salary Sum System 2000' )
13+ print ('-' * 50 )
14+
15+ # Get params from user
16+ print ("Please enter staff name" )
17+ staff_name = input ("Enter Name :" )
18+ print ("Please enter staff type. L for Lecturer, C for Clerk" )
19+ staff_type = input ("Type (L or C) :" )
20+ ot_hours = int (0 )
21+ salary = int (0 )
22+
23+ match staff_type .upper ():
24+ case "L" :
25+ base_salary = sal_lecturer
26+ ot_rate = sal_lecturer_ot
27+ allowance = sal_lecturer_allowance
28+ staff_label = "Lecturer"
29+
30+ case "C" :
31+ ot_hours = int (input ("Please enter OT hours: " ))
32+ base_salary = sal_clerk
33+ ot_rate = sal_clerk_ot
34+ allowance = sal_clerk_allowance
35+ staff_label = "Clerk"
36+
37+ case _:
38+ staff_label = "Unknown"
39+ base_salary = int (0 )
40+ ot_rate = int (0 )
41+ allowance = int (0 )
42+ ot_hours = int (0 )
43+
44+ salary = base_salary
45+ salary += (ot_hours * ot_rate )
46+ salary += allowance
47+
48+ # Output result
49+ print (f'{ staff_name } is a { staff_label } ' )
50+ print (f' Base Salary : £{ base_salary :8} ' )
51+ print (f' OT Hours : { ot_hours :8} ' )
52+ print (f' OT Rate : £{ ot_rate :8} ' )
53+ print (f' Allowance : £{ allowance :8} ' )
54+ print (f' Total Salary: £{ salary :8} ' )
You can’t perform that action at this time.
0 commit comments