0% found this document useful (0 votes)
36 views12 pages

Assignment On If

Uploaded by

sucheta vij
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views12 pages

Assignment On If

Uploaded by

sucheta vij
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

MATA GUJRI PUBLIC SCHOOL

COMPUTER SCIENCE ASSIGNMENT ON IF STATEMENTS


CLASS – XI A 09.07.2020
Q1. Multiple choice questions:
(1) In a Python program, a control structure:
(a) directs the order of execution of the statements in the program.
(b) directs what happens before the program starts and after it ends.
(c) manages the input and output
(d) all of the above
(2) An empty / null statement in python is _____________:
(a) go (b) pass (c) over (d) break
(3) The order of statement execution in the form of top to bottom is known as
_________ construct.
(a) selection (b) repetition (c) sequence (d) flow
(4) The ___________ construct allows to choose statements to be executed
depending upon the result of a condition.
(a) selection (b) repetition (c) sequence (d) flow
(5) The _________ construct repeats a set of statements a specified number of
times or as long as a condition is true.
(a) selection (b) repetition (c) sequence (d) flow
(6) Which of the statements will make a repetition construct?
(a) if (b) if – else (c) for (d) while
(7) Which of the following statements will make a repetition construct?
(a) if (b) if – else (c) for (d) while
(8) In Python, which of the following will create a block in a compound
statement?
(1)
(a) colon
(b) { }
(c) statements indented at a lower, same level
(d) None of these
(9) What signifies the end of a statement block or suite in Python?
(a) A comment (b) } (c) end
(d) A line that is indented less than the previous line
(10) Which of the following if statements will not execute successfully?
(a) if(1, 2): (b) if(1, 2)
print(“Great”) print(“Great”)
(c) if (1, 2): (d) if(1):
print(“Great”) print(“Great”)
(11) What does the following code display?
if True:
print(“101”)
else:
print(“102”)
(a) 101 (b) 202 (c) 303 (4) 102
Q2. Rewrite the following code fragment that saves on the number of
comparisons:
if a==0:
print(“Zero”)
if a==1:
print(“One”)
if a==2:

(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)

a=int{input("ENTER FIRST NUMBER")}

b=int(input("ENTER SECOND NUMBER"))

c=int(input("ENTER THIRD NUMBER"))

if a>b and a>c


(4)
print("A IS GREATER")

if b>a and b>c:

Print(" B IS GREATER")

if c>a and c>b:

print(C IS GREATER)

Ans:

a=int(input("ENTER FIRST NUMBER"))

b=int(input("ENTER SECOND NUMBER"))

c=int(input("ENTER THIRD NUMBER"))

if a>b and a>c:

print("A IS GREATER")

if b>a and b>c:

print (" B IS GREATER")

if c>a and c>b:

print(“C IS GREATER”)

(3)

a,b = 0

if (a = b)

a +b = c

print( z)
(5)
Ans:

a,b = 0, 0 OR a=b=0 OR a=0 ; b=0

if (a = =b):

c=a+b

print(c) #since z is not defined in the program

(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”)

Q5. Write valid if statements for the following conditions:


(1) Either a is greater than b or a is less than c.
if a>b or a<c:
(2) Name is Aman and age is between 18 and 35.
if Name==”Aman” and (age>=18 and age<=35):
(3) Place is either ‘Delhi’ or ‘Goa’ but not ‘Jaipur’
if (place == ‘Delhi’ or place==’Goa’) and place!=’Jaipur’:
(4) Mark is greater than or equal to 70 but less than 100.
if Mark>=70 and Mark<100:
(5) Num is between 0 and 5 but not equal to 2.
if (Num>=0 and Num<=5) and Num!=2:
(6) Answer is either ‘N’ or ‘n’.
if Answer in ‘Nn’:
(7) Age is greater than or equal to 18 and gender is male.
if Age >=18 and gender==”male”:
(8) City is either ‘Kolkata’ or ‘Bangalore’.
if City in [‘Kolkata’,’Bangalore’]:
OR
if City in (‘Kolkata’,’Bangalore’):
OR

(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)

You might also like