Conditional and Iterative Statements || Sumita Arora || Class 11 || Practical || Computer Science || Solution


P.I.P: - 4.1











 
(a) The user enters:0 for x; 1 for y, and 1 for z
(b) The user enters:-1 for x 50 for y, and 100 for z
(c) The user enters:10 for x; 50 for y, and 15 for z
(d) The user enters:-1 for x; -50 for y, and -100 for z



For k's this value Output Flow-of-execution
(i) 79
(ii) 29
(iii) 39
(iv) 59
(v) 30
(vi) 50
(vii) 60


S. No. Input values Output produced
(a) x = 2 and y = 5?
(b) x = 3 and y = 1?
(c) x = 1 and y = 1?
(d) x = 4 and y = 3?




















Code Output
(a) if not 3:
    print ("Tricky \n")
print ("Yes")

(b) if 3:
    print ("Tricky again")
else:
    print ("Am I right?")
    print ("No???")

(c) if (0):
    print ("Third time Tricky")
    print ("Am I right?")

(d) if (not 0):
    print ("Fourth time again \n")
    print ("No??")

(e) if 0:
    print ("Plz! Not again \n")
else:
    print ("Promise, it's the last time")
print ("Thank God!!")








Grade Remarks Marks
A (Level 4, above agency-normalized standards) 80% and above
B (Level 3, at agency-normalized standards) 70-79%
C (Level 2, below, but approaching agency-normalized standards) 60-69%
D (Level 1, well below agency-normalized standards) 50-59%
E (Level 1-, too below agency-normalized standards) 40-49%


P.I.P: - 4.2



Program Code Dry run (determine output on paper) Actual output (run code and find out)
(a) for a in 10, 12, 14, 16, 18:
    print (a)
(b) for i in range (5):
    print (i)
(c) for i in range (0,5):
    print (j)
(d) for k in range (3,0):
    print (k)
(e) for c in "Apple":
    print (c)
Program Code Dry run (determine output on paper) Actual output code and find (run out)
(a) a = 8
while (a > 0):
    print ("Gotcha!")
    a = a - 3
else:
    print ("Going out!")


(b) a = 8
while (a > 0):
    print ("Gotcha!")
else:
    print ("Going out!")


(c) a = 8
while (a > 0):
    print ("Gotcha!")
    a = a + 3
else:
    print ("Going out!")


(d) a = 8
while (a > 0):
    print ("Gotcha!")
    a = a - 3
    ifa ==5:
        break
else:
    print ("Going out!")


i = 0
while i < 10:
    i +=1
    if i % 2 == 0:
        print(i)
i = 0
while i > 10:
    i +=1
    if i % 2 == 0:
        print(i)
i = 0
while i < 1:
    i -= 1
    if i % 2 == 0:
        print(i)














Given Correct Code
for iMus range (10)
b = 19 + iMus
    print (b)
while k < 10 :
print (k)
k = k + 2
a = 5
while a < 10:<10: 1="" 2="" a="" deg="" else="" print="" td="">
a = 5
while a
    print (a)
    a -=1
For p in range (3)
    for q in range (3)
        print (p * q)
    else:
    print ("outer loop ends")
for p in range(3)
    for q in range(3)
        print ( p * q)
    elif:
    print ("loop ends")
else:
    print ("loop over")
(a) j = 0
while (j < 50):
    print ("Hello World")
(b) j = 25
while (25 <= j <= 30):
    print ("Temp variable = ", j)
    j = j + 1
(c) j = 25
while (25 <= j < 30):
    print ("Temp variable =", j)
    j = j + 1
(d) # Assume Boolean variable b is not known
b = True
sum = 0
while b:
    sum = sum + 5
    print (sum)
    if (b or not b):
        break
(e) a = 1.0
for i in range (1,4):
    a = a * 3
print (a)
print (j)
(f) a = 1.0
for j in range (4):
    a = a * j
print (a)
print (j)
(g) for j in 'abcde':
    print (j, end = '')
    if j > 'c':
        break


































Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post