-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path22. Nested-if-else-elif.py
48 lines (41 loc) · 1.09 KB
/
22. Nested-if-else-elif.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
# 1. Nested if statements
num = int(input("Enter a number : "))
if num <=100:
print("Number is less than 100.")
if num%2==0:
print("Number is multiple of 2")
if num%3==0:
print("Number is multiple of 3")
if num%5==0:
print("Number is multiple of 5")
if num%7==0:
print("Number is multiple of 7")
if num>1 and num%2!=0 and num%3!=0 and num%5!=0 and num%7!=0:
print("Number is prime!")
else:
print("Number is not less than or equal to 100!")
print()
"""
OUTPUT -
Enter a number : 487
Number is not less than or equal to 100!
"""
# 2. Nested if, elif and else statements
height = int(input("Enter your height in cms : "))
if height>100:
print("You can ride!")
age = int(input("Enter your age : "))
if age <12:
print("Please, pay 100 rs!")
elif age <=18:
print("Please, pay 150 rs!")
else:
print("Please pay 250 rs!")
else:
print("You can't ride!")
print("Bye, thanks for choosing us!")
"""
OUTPUT -
Enter your height in cms : 170
You can ride!
"""