-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathif-else.py
More file actions
73 lines (63 loc) · 1.45 KB
/
if-else.py
File metadata and controls
73 lines (63 loc) · 1.45 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
# If-Else Example
def check_number(num):
if num > 0:
return "Positive"
elif num < 0:
return "Negative"
else:
return "Zero"
# Test the function
print(check_number(10))
print(check_number(-5))
print(check_number(0))
# More Examples If-Else Conditions Any Situation
def check_age(age):
if age < 18:
return "Minor"
elif age < 65:
return "Adult"
else:
return "Senior"
# Test the function
print(check_age(10))
print(check_age(30))
print(check_age(70))
# Additional Examples If-Else Conditions Any Situation
def check_temperature(temp):
if temp > 30:
return "Hot"
elif temp > 20:
return "Warm"
else:
return "Cold"
# Test the function
print(check_temperature(35))
print(check_temperature(25))
print(check_temperature(15))
# Use Operator Like != == > < >= <=
def check_value(x):
if x != 10:
return "Not Ten"
elif x == 10:
return "Ten"
elif x > 10:
return "Greater than Ten"
else:
return "Less than Ten"
# Test the function
print(check_value(10))
print(check_value(5))
print(check_value(15))
print(check_value(10))
# Use Operator Logical And Or Not
def check_logic(a, b):
if a > 0 and b > 0:
return "Both positive"
elif a < 0 or b < 0:
return "At least one negative"
else:
return "Both zero"
# Test the function
print(check_logic(10, 5))
print(check_logic(-10, 5))
print(check_logic(0, 0))