forked from inspirezonetech/TeachMePythonLikeIm5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
if-else.py
52 lines (40 loc) · 1.57 KB
/
if-else.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
# ------------------------------------------------------------------------------------
# Tutorial: Lets learn how to use if else
# ------------------------------------------------------------------------------------
# For this example we are programming a game that uses lives,
# if a user runs out of lives the program will display a game
# over message.
lives = 0
if lives == 0: # the variable lives is equal to 0.
print("Game Over.")
elif lives != 0: # the variable lives is not equal to 0.
print("Ha Ha Ha, Staying Alive.")
# For example if we want play a game that is rated 12 years and up
# Lets write a program to check if you can play that game.
age = 13
if age >= 12:
print("Yes, you can play that game.")
else:
print("Lets find a better game for you.")
# We can also use elif do a chain of conditions
# like this:
if age < 18:
print("Can't join army")
elif age > 35:
print("Can't join army")
else:
print("Can join army!")
# ------------------------------------------------------------------------------------
# Challenge: Using your knowledge of operators, write two conditions where it
# says "replace-me", to check if your car is going below speed limit and above
# the minimum speed for the street.
# ------------------------------------------------------------------------------------
street_max_speed = 100
street_min_speed = 50
car_speed = 70
if "replace_me":
print("Lower your speed or you will be penalized")
elif "replace_me":
print("You should get a higher speed")
else:
print("Ok, you are in a good speed to travel")