-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConditional statement if
More file actions
121 lines (96 loc) · 1.89 KB
/
Conditional statement if
File metadata and controls
121 lines (96 loc) · 1.89 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
Conditional Statement
1. if
if test-condition:
----------
----------
----------
----------
2. if then else
if test-condition:
----------
----------
----------
----------
else:
----------
----------
----------
3. if elif then else=multioptional/Ladder of if
if test-condition:
----------
----------
----------
----------
elif test-condition:
----------
----------
----------
elif test-condition:
---------
---------
---------
---------
.
.
else:
--------
--------
--------
--------
4. nested if(if inside another if is know as nested if)
if test-condition: #outter if
-----------
-----------
-----------
if Test-condition: #inner if
----------
----------
----------
else:
----------
----------
----------
else:
--------
--------
--------
--------
if 3>2:
#start block/indentation level
print("True")
print("correct")
#exit from if /end indentation--back one level of indentation
else:
print("false")
print("incorrect")
>>> x,y=10,20
>>> x,y=y,x
>>> print("x=",x)
x= 20
>>> print("y=",x)
y= 20
>>> print("y=",y)
y= 10
>>> x,y,z=10,20,30
>>> x,y,z=z,x,y
>>> print(x)
30
>>> print(y)
10
>>> print(z)
20
>>>
[8:52 PM, 12/24/2020] Sushil Sir C++: num1=float(input("Enter first value:"))
num2=float(input("Enter second value:"))
#compare(only if)
if num1>num2:
print(num1,"value is big")
if num2>num1:
print("Big value is ",num2)
num1=float(input("Enter first value:"))
num2=float(input("Enter second value:"))
#compare(only if)
if num1>num2:
print(num1,"value is big")
else:
print("Big value is ",num2)