Assignment On If
Assignment On If
(2)
print(“Two”)
if a==3:
print(“Three”)
Ans:
if a==0:
print(“Zero”)
elif a==1:
print(“One”)
elif a==2:
print(“Two”)
elif a==3:
print(“Three”)
Q3. Under which condition the following code will print “water”?
if temp<32:
print(“ice”)
elif temp<212:
print(“water”)
else:
print(“steam”)
Ans:
When temp>=32 and temp<212
Q4. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
(1)
(3)
weather='raining'
if weather='sunny':
print("wear sunblock")
elif weather='snow':
print("going skiing")
else:
print(weather)
Ans:
weather='raining'
if weather=='sunny':
print("wear sunblock")
elif weather=='snow':
print("going skiing")
else:
print(weather)
(2)
Print(" B IS GREATER")
print(C IS GREATER)
Ans:
print("A IS GREATER")
print(“C IS GREATER”)
(3)
a,b = 0
if (a = b)
a +b = c
print( z)
(5)
Ans:
if (a = =b):
c=a+b
(4)
if n==0
print(“zero”)
elif : n==1
print(“one”)
elif
n==2:
print(“two”)
else n==3:
print(“three”)
Ans:
if n==0:
print(“zero”)
elif n==1:
print(“one”)
(6)
elif n==2:
print(“two”)
elif n==3:
print(“three”)
(7)
if City==’Kolkata’ or City==’Bangalore:
Q6. What will be the output of the following code segment?
(1) x=3
if x==0:
print("Am I here?",end='')
elif x==3:
print("Or here?",end='')
else:
pass
print("Or over here?")
Ans:
Or here?Or over here?
(2)
x=2
if x==1:
print("yes")
elif x>=2:
print("Maybe")
else:
print("No")
Ans:
Maybe
(3) if(4 + 5==10):
print(“TRUE”)
else:
(8)
print(“FALSE”)
print(“TRUE”)
Ans:
FALSE
TRUE
(4)
x=1
if x>3:
if x>4:
print("A",end='')
else:
print("B",end='')
elif x<2:
if x!=0:
print("C",end='')
print("D")
Ans:
CD
(5)
if int('0')==0:
print("zero")
elif str(0)=='zero':
print(0)
elif str(0)=='0':
print(str(0))
(9)
else:
print("None of the above")
Ans:
zero
(6)
a=3
a=a+1
if a>5:
print(a)
else:
print(a+5)
Ans:
9
(7)
NoOfGirls = 4
NoOfBoys = 10
if NoOfBoys == 8 and NoOfGirls <= NoOfBoys : ------ False
print("Great achievement")
else:
print("Greater achievement")
Ans:
Greater achievement
(10)
(8)
circle=5
rectangle=0
square=4
triangle = 0
if circle:
if rectangle or square:
print("Draw diagram")
elif not rectangle and not square:
print("Invalid diagram");
else:
if circle == rectangle or square == triangle:
print("Canvas Available")
print("Invisible diagram")
Ans:
Draw Diagram
Invisible Diagram
(9) [not, and, or]
x=3
if x>2 or x<5 and x==6:
print("ok")
else:
print("No output")
Ans:
No output
(11)
(10)
x=50
if x>10: ---- True
if x>25: ---- True
print("ok")
if x>60: ---- False
print("good")
elif x>40: ----- True
print("average")
else:
print("no output")
Ans:
ok
average
(12)