-
Notifications
You must be signed in to change notification settings - Fork 0
/
Conditions.py
78 lines (58 loc) · 1.33 KB
/
Conditions.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
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
# Conditional Statements
## IF
# if test expression:
# Body of if
# Example:
A = 20
B = 30
C = A+B
if C>50:
print("Answer is greater than 50")
if C<50:
print("Answer is less than 50")
## One line if statement:
if A > B: print("A is greater than B")
## Else IF
# if test expression:
# Body of if
# elif:
# Body of elif
# else:
# Body of else
#Example
A = 20
B = 30
C = A+B
if C>50:
print("Answer is greater than 50")
elif C<50:
print("Answer is less than 50")
else:
print("Answer equal to 50")
## Nested IF
num = float(input("Enter a number: "))
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
## and
num_1 = float(input("Enter a number: "))
num_2 = float(input("Enter a number: "))
if num_1 > 10 and num_2 > 10 :
print("Both numbers are greater than 10")
elif num_1 < 10 and num_2 < 10 :
print("Both numbers are less than 10")
else:
print("Something else")
## or
num_1 = float(input("Enter a number: "))
num_2 = float(input("Enter a number: "))
if num_1 > 10 or num_2 > 10 :
print("One of the number is greater than 10")
elif num_1 < 10 or num_2 < 10 :
print("One of the number is less than 10")
else:
print("Something else")