Skip to content

Commit f9ec61d

Browse files
authored
End of Assignment 2
1 parent 79adf28 commit f9ec61d

File tree

11 files changed

+268
-11
lines changed

11 files changed

+268
-11
lines changed

Assessment/Wk2/cost_of_living.jpg

208 KB
Loading

Assessment/Wk2/cost_of_living.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# calculate total cost of living
2+
3+
##
4+
# Helpers
5+
##
6+
7+
## function to get a float with error checking
8+
def get_float(input_prompt, min_val=float(0.01), max_val=float(100.00)):
9+
return_value=float(0.0)
10+
float_val=float(-1)
11+
12+
try:
13+
while not ((float_val >= min_val and float_val <= max_val)) :
14+
get_val=input(input_prompt + f" (Min: {str(min_val)} Max: {str(max_val)} Exit: 0)")
15+
float_val=float(get_val)
16+
17+
## exit if select 0
18+
if float_val==0:
19+
break
20+
21+
return_value=float_val
22+
except:
23+
print ( f"Invalid '{input_prompt}' value entered '{get_val}'" )
24+
finally:
25+
return return_value
26+
27+
print ( 'Monthly Cost adder upper')
28+
print ( '-' * 25 )
29+
30+
#Input
31+
rent=get_float("Rent per month",float(0.01),float(9999.99))
32+
gas=get_float("Gas payment per month",float(0.01),float(9999.99))
33+
elec=get_float("Electric payment per month",float(0.01),float(9999.99))
34+
water=get_float("Water payment per month",float(0.01),float(9999.99))
35+
council=get_float("Council tax payment per month",float(0.01),float(9999.99))
36+
total = rent + gas + elec + water + council
37+
38+
# Output
39+
print ( 'Your monthly expenses are:')
40+
print ( f'{"Rent:":16}£{rent:8.2f}')
41+
print ( f'{"Gas:":16}£{gas:8.2f}')
42+
print ( f'{"Electricity:":16}£{elec:8.2f}')
43+
print ( f'{"Water:":16}£{water:8.2f}')
44+
print ( f'{"Council Tax:":16}£{council:8.2f}')
45+
print ( "=" * 25)
46+
print ( f'{"Total:":16}£{total:8.2f}')
47+
print ( "=" * 25)

Assessment/Wk2/cuboid.jpg

217 KB
Loading

Assessment/Wk2/cuboid.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Calculate cuboid stats
2-
2+
###
33
# helpers
4-
4+
###
55
## function to get an integer with error checking
66
def get_int(input_prompt, min_val=int(1), max_val=int(100)):
77
return_value=int(0)
88
int_val=int(-1)
99

1010
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)")
11+
while not ((int_val >= min_val and int_val <= max_val)) :
12+
get_val=input(input_prompt + f" (Min: {str(min_val)} Max: {str(max_val)} Exit: 0)")
1313
int_val=int(get_val)
1414

1515
## exit if select 0
@@ -22,23 +22,20 @@ def get_int(input_prompt, min_val=int(1), max_val=int(100)):
2222
finally:
2323
return return_value
2424

25-
26-
2725
# params
2826
min_int=int(1)
2927
max_int=int(100)
3028

3129
print ( 'Welcome to the Cuboid Calculator' )
32-
print ( '-' * 40 )
30+
print ( '-' * 32 )
3331

3432
cub_width=get_int("Width (cm): ")
3533
cub_height=get_int("Height (cm): ")
3634
cub_length=get_int("Length (cm): ")
3735

38-
print (type(cub_width))
39-
print (type(cub_height))
40-
print (type(cub_length))
41-
36+
# print (type(cub_width))
37+
# print (type(cub_height))
38+
# print (type(cub_length))
4239

4340
if ( cub_width > int(0) and cub_height > int(0) and cub_length > int(0) ) :
4441
surface= 2 * ( ( cub_width * cub_height ) + ( cub_height * cub_length ) + ( cub_length * cub_width ) )
197 KB
Loading
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## distance calculator for calculating distances.
2+
3+
##
4+
# Helpers
5+
##
6+
7+
## function to get an integer with error checking
8+
def get_int(input_prompt, min_val=int(1), max_val=int(100)):
9+
return_value=int(0)
10+
int_val=int(-1)
11+
12+
try:
13+
while not ((int_val >= min_val and int_val <= max_val)) :
14+
get_val=input(input_prompt + f" (Min: {str(min_val)} Max: {str(max_val)} Exit: 0)")
15+
int_val=int(get_val)
16+
17+
## exit if select 0
18+
if int_val==0:
19+
break
20+
21+
return_value=int_val
22+
except:
23+
print ( f"Invalid '{input_prompt}' value entered '" + get_val + "'" )
24+
finally:
25+
return return_value
26+
27+
28+
29+
# The formula you will need to perform the calculation is:
30+
# 𝑠=𝑢𝑡+ 1/2(𝑎𝑡2)
31+
# where
32+
# 𝑠 = distance
33+
# 𝑢 = initial velocity
34+
# 𝑡 = time taken
35+
# 𝑎 = acceleration
36+
37+
print ( 'Distance Calculator ' )
38+
print ( '-' * 42 )
39+
40+
## get values
41+
val_u = get_int("Initial Velocity")
42+
val_t = get_int("Time taken")
43+
val_a = get_int("Acceleration")
44+
45+
val_s = (val_u * val_t) + (0.5 * val_a * (val_t * val_t))
46+
47+
print ( f'An object travelling with initial velocity {val_u} m/s')
48+
print ( f'Accelerating at a constant rate of {val_a} m/s/s')
49+
print ( f'For {val_t} seconds ')
50+
print ( f'Will have travelled {val_s} meters ')
51+

Assessment/Wk2/helpers.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
## function to get an integer with error checking
3+
def get_int(input_prompt, min_val=int(1), max_val=int(100)):
4+
return_value=int(0)
5+
int_val=int(-1)
6+
7+
try:
8+
while not ((int_val >= min_val and int_val <= max_val)) :
9+
get_val=input(input_prompt + f" (Min: {str(min_val)} Max: {str(max_val)} Exit: 0)")
10+
int_val=int(get_val)
11+
12+
## exit if select 0
13+
if int_val==0:
14+
break
15+
16+
return_value=int_val
17+
except:
18+
print ( f"Invalid '{input_prompt}' value entered '" + get_val + "'" )
19+
finally:
20+
return return_value
21+
22+
23+
## function to get a float with error checking
24+
def get_float(input_prompt, min_val=float(0.01), max_val=float(100.00)):
25+
return_value=float(0.0)
26+
float_val=float(-1)
27+
28+
try:
29+
while not ((float_val >= min_val and float_val <= max_val)) :
30+
get_val=input(input_prompt + f" (Min: {str(min_val)} Max: {str(max_val)} Exit: 0)")
31+
float_val=float(get_val)
32+
33+
## exit if select 0
34+
if float_val==0:
35+
break
36+
37+
return_value=float_val
38+
except:
39+
print ( f"Invalid '{input_prompt}' value entered '{get_val}'" )
40+
finally:
41+
return return_value

Assessment/Wk2/seconds.jpg

199 KB
Loading

Assessment/Wk2/seconds.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Convert seconds into hours, minutes, seconds.
2+
3+
##
4+
# Imports
5+
# ##
6+
from datetime import timedelta
7+
8+
##
9+
# Helpers
10+
##
11+
12+
## function to get an integer with error checking
13+
def get_int(input_prompt, min_val=int(1), max_val=int(100)):
14+
return_value=int(0)
15+
int_val=int(-1)
16+
17+
try:
18+
while not ((int_val >= min_val and int_val <= max_val)) :
19+
get_val=input(input_prompt + f" (Min: {str(min_val)} Max: {str(max_val)} Exit: 0)")
20+
int_val=int(get_val)
21+
22+
## exit if select 0
23+
if int_val==0:
24+
break
25+
26+
return_value=int_val
27+
except:
28+
print ( f"Invalid '{input_prompt}' value entered '" + get_val + "'" )
29+
finally:
30+
return return_value
31+
32+
print ( 'Time converter v0.1')
33+
print ( '-' * 42 )
34+
35+
# Get the input of seconds
36+
var_seconds = get_int("Enter Number of Seconds",int(1),int(86399))
37+
38+
# output the result
39+
tmp_conv=str(timedelta(seconds=var_seconds))
40+
41+
a_parts=tmp_conv.split(":")
42+
43+
print ( f'{"Input":6} {"Hours":>10} {"Minutes":>10} {"Seconds":>10} ')
44+
print ( f'{var_seconds:<6} {int(a_parts[0]):10} {int(a_parts[1]):10} {int(a_parts[2]):10} ')

Assessment/Wk2/weekly_shop.jpg

253 KB
Loading

0 commit comments

Comments
 (0)