Skip to content

Commit 9cc20b4

Browse files
authored
After lecture 3
1 parent 72f05f6 commit 9cc20b4

18 files changed

+192
-3
lines changed

Assessment/Wk3/average.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# basic average calculator
2+
3+
num1 = int(input("Enter first integer: "))
4+
num2 = int(input("Enter second integer: "))
5+
num3 = int(input("Enter third integer: "))
6+
num4 = int(input("Enter fourth integer: "))
7+
8+
avg= ( num1 + num2 + num3 + num4 ) / 4
9+
print ( "For values: ", num1 , num2 , num3 , num4 )
10+
print ("Average is: " + str(avg))

Assessment/Wk3/average_test.docx

131 KB
Binary file not shown.

Assessment/Wk3/bandwidth.jpg

125 KB
Loading

Assessment/Wk3/bandwidth.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Bandwidth Headache
2+
3+
4+
# inits
5+
6+
m_in_b = int(1000000)
7+
app_a_bw = int(200000)
8+
app_b_bw = int(100000)
9+
app_new_bw = int(350000)
10+
11+
max_bw_M = int(1000 )
12+
max_bw_b = max_bw_M * m_in_b
13+
14+
conc_users = int(200)
15+
16+
# calcs
17+
current_usage = conc_users * ( app_a_bw + app_b_bw )
18+
free_capacity = max_bw_b - current_usage
19+
new_app_demands = conc_users * app_new_bw
20+
spare_after = max_bw_b - current_usage - new_app_demands
21+
22+
# outputs
23+
print ( "Bandwidth guesstimator 1000 ")
24+
print ( "-" * 30 )
25+
26+
print ( f'Maximum network bandwidth is { max_bw_b } bps')
27+
print ( f'Current network usage is { current_usage } bps' )
28+
print ( f'Current availability is { free_capacity } bps' )
29+
print ( f'New application requirements are { new_app_demands } bps')
30+
print ( f'Spare Bandwidth available is new app deployed is { spare_after / m_in_b } Mbps ')
178 KB
Loading
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# converts imperial values to metric
2+
3+
## function to get an integer with error checking
4+
def get_int(input_prompt, min_val=int(1), max_val=int(100)):
5+
return_value=int(0)
6+
int_val=int(-1)
7+
8+
try:
9+
while not ((int_val >= min_val and int_val <= max_val)) :
10+
get_val=input(input_prompt + f" (Min: {str(min_val)} Max: {str(max_val)} Exit: 0)")
11+
int_val=int(get_val)
12+
13+
## exit if select 0
14+
if int_val==0:
15+
break
16+
17+
return_value=int_val
18+
except:
19+
print ( f"Invalid '{input_prompt}' value entered '" + get_val + "'" )
20+
finally:
21+
return return_value
22+
23+
24+
# inits
25+
inch_factor = float(2.54)
26+
27+
print ( "Imperial converter ")
28+
print ( "-" * 25 )
29+
30+
# get user input
31+
print ( 'Please enter your height in feet and inches')
32+
usr_height_feet = get_int("Enter feet :",1,9)
33+
usr_height_inches = get_int("Enter inches : ",1,12)
34+
35+
# calcs
36+
usr_h_in = ( usr_height_feet * 12 ) + usr_height_inches
37+
usr_h_cm = usr_h_in * inch_factor
38+
39+
# output
40+
41+
print ( f"User's imperial height is { usr_height_feet }' { usr_height_inches }\" " )
42+
print ( f"Height in kilometres: { usr_h_cm / 100000 }")
43+
print ( f"Height in metres: { usr_h_cm / 100 }")
44+
print ( f"Height in centimetres: { usr_h_cm }")
45+
print ( f"Height in millimetres: { usr_h_cm * 10 }")
46+
47+

Assessment/Wk3/telephone_bill.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Calculate a phone call cost.
2+
3+
## function to get an integer with error checking
4+
def get_int(input_prompt, min_val=int(1), max_val=int(100)):
5+
return_value=int(0)
6+
int_val=int(-1)
7+
8+
try:
9+
while not ((int_val >= min_val and int_val <= max_val)) :
10+
get_val=input(input_prompt + f" (Min: {str(min_val)} Max: {str(max_val)} Exit: 0)")
11+
int_val=int(get_val)
12+
13+
## exit if select 0
14+
if int_val==0:
15+
break
16+
17+
return_value=int_val
18+
except:
19+
print ( f"Invalid '{input_prompt}' value entered '" + get_val + "'" )
20+
finally:
21+
return return_value
22+
23+
# inits
24+
call_rate=int(15)
25+
vat_rate=float(0.2) ## 20%
26+
27+
# Get user data
28+
num_mins=get_int("Please enter the number of minutes used: ", 1, 9999)
29+
30+
# calcs
31+
basic_charge = num_mins * call_rate ## in pence
32+
vat_charge = basic_charge * vat_rate ## again in pence
33+
34+
# output
35+
print ( f'Number of minutes used: {num_mins}')
36+
print ( f'Basic call charge: £{(basic_charge/100):.2f}')
37+
print ( f'VAT due: £ {(vat_charge/100):.2f}') ## this spurious space after the £ was in the spec...
38+
print ( f'Total bill: £{((basic_charge+vat_charge)/100):.2f}')
75.2 KB
Binary file not shown.
10.1 KB
Loading
8.98 KB
Loading

0 commit comments

Comments
 (0)