-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path08_conditionals.py
More file actions
42 lines (35 loc) · 1.13 KB
/
08_conditionals.py
File metadata and controls
42 lines (35 loc) · 1.13 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
# Check whether the given number is greater than 10 or not
user_input = int(input("Enter a number:"))
# user_input = int(user_input)
# if user_input > 10:
# print("User input value is greater than 10")
# else:
# print("User input value is less than or equal 10")
# Check whether the given number is equal to 10 or greater than 10 or less than 10 or something else
# Method 1: Nested if-else
if user_input == 10:
print("Right on target")
else:
if user_input > 10:
print("User input value is greater than 10")
else:
if user_input < 10:
print("User input value is less than 10")
# Method 2
if user_input == 10:
print("Right on target")
elif user_input > 10:
print("User input value is greater than 10")
else:
print("User input value is less than 10")
# Exception handling: try - except
try:
user_input = int(input("Enter a number:"))
if user_input == 10:
print("Right on target")
elif user_input > 10:
print("User input value is greater than 10")
else:
print("User input value is less than 10")
except ValueError:
print("Please enter a number")