-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculating Speed Limit with User input validation.py
58 lines (39 loc) · 2.05 KB
/
Calculating Speed Limit with User input validation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#######################################################
#Name: Liela Pressley
# Class: CIS-1400
# Assignment: Homework 7 Fall 2020
# File: Homework_07.py
# Purpose: Calculating Speed Limit with User input validation
#######################################################
#enter a speed limit
#using that speedllimit as a variable then do a while loop using the speedlimitchart
#under the while loop restricts print the fine.
#have to set another while loop for speed limit entry restrictions (set a function)
def main():
speedlmt = speed_limit() #assigning variable to function for speed limit
user_speed=vehicle_speed() #assigning variable to function for speed limit
if user_speed <speedlmt:
print('ERROR- Invalid speed entered...')
user_speed=vehicle_speed() #assigning variable to function for speed limit
speeding_fine = user_speed - speedlmt #calculating the fine
if speeding_fine <= 10 and speeding_fine >= 1: #after the calculations the different fines are assigned and printed
print('Exceeded speeding limit by 1-10 MPH. $50 fine.')
elif speeding_fine >= 11 and speeding_fine <=15:
print('Exceeded speeding limit by 11-15 MPH. $75 fine.')
elif speeding_fine >= 16 and speeding_fine <=20:
print('Exceeded speeding limit by 16-20 MPH. $150 fine.')
elif speeding_fine >=21:
print('Exceeded speeding limit by 21+ MPH. $300 fine.')
def speed_limit():
limit = int(input('Please enter the speed limit: ' ))
while limit < 20 or limit >70: #restricts user input of speed limit to 20-70 mph
print('ERROR-Please enter speed limit between 20-70 mph.')
limit = int(input('Please enter the speed limit: ' ))
return limit
def vehicle_speed():
actual_speed = int(input('Please enter your speed: '))
while actual_speed > 200: #resticting speed enter if greater than 200 then returning it to variable
print('ERROR- Invalid speed entered...')
actual_speed = int(input('Please enter your speed: '))
return actual_speed
main()