-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_conditional.py
More file actions
128 lines (95 loc) · 2.22 KB
/
10_conditional.py
File metadata and controls
128 lines (95 loc) · 2.22 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Question No 1.
# Get a score value from the user.
userScore = input("Give me a score value: \n")
print("User score (as string):", userScore)
# Convert to integer.
userScore_in_int = int(userScore)
print("User score (as integer):", userScore_in_int)
age = input("Please provide me age: ")
age = int(age)
if age < 13:
print("chai")
elif age <= 20:
print("Teenager")
elif age < 60:
print("Adult")
else:
print("senior")
# Question No 2.
age = 22
day = "wednesday"
price = 12 if age >= 18 else 8
if day == "wednesday":
price = price - 2
print("Ticket price for you is $:", price)
# Question No 3.
score = 85
if score >= 101:
print("You are not allowed to input grade greater than 100")
exit()
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
elif score >= 60:
grade = "D"
else:
grade = "F"
print("Grade:", grade)
# Question No 4.
fruit = "Banana"
color = "Yellow"
if fruit == "Banana":
if color == "Green":
print("Unripe")
elif color == "Yellow":
print("Ripe")
elif color == "Brown":
print("Overripe")
else:
print("Nothing")
# Question No 5.
weather = "Sunny"
if weather == "Sunny":
activity = "Go for a walk"
elif weather == "Rainy":
activity = "Read a book"
elif weather == "Snowy":
activity = "Build a snowman"
else:
activity = "Stay indoors"
print("Activity:", activity)
# Question No 6.
distance = 5
if distance < 3:
transport = "walk"
elif distance <= 15:
transport = "Bike"
else:
transport = "Car"
print("AI recommends you the transport:", transport)
# Question No 7.
order_size = "Medium"
extra_shot = True
if extra_shot:
coffee = order_size + " coffee with an extra shot"
else:
coffee = order_size + " coffee"
print("Order:", coffee)
# Question No 8.
password = "Secure3P@ss"
if len(password) < 6:
strength = "weak"
elif len(password) <= 10:
strength = "Medium"
else:
strength = "Strong"
print("Password strength is:", strength)
# Question No 9.
year = 2023
if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
print(year, "is a leap year")
else:
print(year, "is not a leap year")