-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConditionalStatements.py
77 lines (57 loc) · 1.4 KB
/
ConditionalStatements.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
age = 21
if(age >= 18):
print("can vote & apply for license")
print("can drive")
light = "green"
if(light=="red"):
print("stop")
elif(light=="green"):
print("go")
elif(light=="yellow"):
print("look")
print("End of code.")
num = 5
if(num>2):
print("greater than 2")
if(num>3): #if statement can be written multiple times and all will be checked
print("greater than 3")
elif(num>4): #if if statement is true then elif statement will not be checked
print("greater than 4")
#elif can also be written multiple time but first their should be one if statement
light = "blue"
if(light=="red"):
print("stop")
elif(light=="green"):
print("go")
elif(light=="yellow"):
print("look")
else:
print("light is broken")
age = 14
if(age >= 18):
print("can vote") #"indentation" means 4 spaces or tab before print
else:
print("cannot vote") # in pyhton indentation is used instead of {}
# For Example
# marks>=90, grade = "A"
# 90>marks>=80, grade = "B"
# 80>marks>=70, grade = "C"
# 70>marks, grade = "D"
marks = int(input("enter students marks : "))
if(marks>=90):
grade = "A"
elif(marks>=80 and marks<90):
grade = "B"
elif(marks>=70 and marks<80):
grade = "C"
else:
grade = "D"
print("garde of the student ->", grade)
#nesting
age = 95
if(age>=18):
if(age>=80):
print("cannot drive")
print("can drive")
else:
print("cannot drive")