-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtesla-exercise-update
54 lines (48 loc) · 2.85 KB
/
tesla-exercise-update
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
#1. Wrap the above code in a function called checkDriverAge(). Whenever you call this function, you will get prompted for age.
def checkDriverAge(age=input("What is your age?: ")):
if int(age) < 18:
print("Sorry, you are too young to drive this car. Powering off")
elif int(age) > 18:
print("Powering On. Enjoy the ride!");
elif int(age) == 18:
print("Congratulations on your first year of driving. Enjoy the ride!")
checkDriverAge()
#2 Instead of using the input(). Now, make the checkDriverAge() function accept an argument of age, so that if you enter:
#checkDriverAge(92);
#it returns "Powering On. Enjoy the ride!"
#also make it so that the default age is set to 0 if no argument is given.
def newcheckDriverAge(age=0):
if int(age) < 18:
print("Sorry, you are too young to drive this car. Powering off")
elif int(age) > 18:
print("Powering On. Enjoy the ride!");
elif int(age) == 18:
print("Congratulations on your first year of driving. Enjoy the ride!")
newcheckDriverAge(92)
# Notice the benefit in having checkDriverAge() instead of copying and pasting the function everytime?
/\ /\
| \ / |
| \ / \ / |
| \ /\ / \ / \ / |
| \ ^ / \/ \/ \ ^ / |
| |
/ \
/ \ / \
/ | \ / | \
/ | \ / | \
/ | @\ /@ | \
/ | \ / | \
/ \___/ \___/ \
/ \
/ |\______________________/| \
/ \ | | | | | | | /\ \
/ / \ | | | | | | | / \ \
/ / \ | | | | | | | / \ \
/ / \ \ | | | | | / / \ \
/ \ \ \_|___|___|___|___|__/ / / \
\/\/\/ /\ /\ \/\/\/
/ \ / \
| |
| \____________________/ |
\ | | /
<_________/ \_________>