-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfElse.py
More file actions
61 lines (53 loc) · 1.38 KB
/
IfElse.py
File metadata and controls
61 lines (53 loc) · 1.38 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
# Program to demonstrate if/else statements.
# Declare variables
a = 7
b = 13
c = 5
tup = (2, 4, 6, 8, 10)
lis = [3, 6, 9, 12, 15]
dict = {"Sons": 3, "Daughters": 1}
# If/else statement
if a > b:
print("a is greater than b")
elif b > a:
print("b is greater than a")
elif a == b:
print("a and be are equal")
else:
print("something is wrong with the values")
# Find which number is greatest
if ((a > b) & (a > c)):
print("a is the highest number")
elif ((b > a) & (b > c)):
print("b is the highest number")
elif ((c > a) & (c > b)):
print("c is the highest number")
else:
print("something is wrong with the values")
# Demonstrate if/else with tuple
if 8 in tup:
print("8 is in the tuple")
else:
print("8 is not in the tuple")
# Demonsrate when value not present in tuple
if 7 in tup:
print("7 is in the tuple")
else:
print("7 is not in the tuple")
# Print list
print(lis)
# If/else with list
if lis[2] == 9:
lis[2] *= 2
print(lis)
else:
print("value is not in list")
# If/else with dictionary
if dict["Sons"] == 3:
print("There are 3 sons in the family.")
elif dict["Sons"] > 3:
print("There are more than 3 sons in the family.")
elif dict["Sons"] < 3:
print("There are less than 3 sons in the familiy.")
else:
print("Something is wrong with the dictionary.")