Python Revision Tour - 1 || Type B || Sumita Arora || Class 12 || Computer science || Solution



Q1. Fill In the missing lines of code in the following code. The code reads in a limit amount a prices and prints the largest price that is less than the limit. You can assume that all prices and the limit are positive numbers. When a price 0 is entered the program terminates and prints the largest price that is less than the limit.

# Read the limit.
limit = float(input ('enter the limit'))
max_price = 0
#Read the next price
next_price = float(input ("Enter a price or to stop:"))
while next_price > 0 :
    <write your code here>
    # Read the next price
    <Write your code here>
if min_price > 0 :
    <Write your code here>
else :
    <Write your code here>





Q2. Predict the outputs of the following programs: -

(a)
count = 0
while count < 10 :
    print ("Hello")
    count += 1

(b)
x = 10
y = 0
while x > y :
    print (x, y)
    x = x - 1
    y += 1

(c)
keepgoing = True
x = 100
while keepgoing :
    print (x)
    x = x - 10
    if x < 50 :
        keepgoing = False

(d)
x = 45
while x < 50 :
    print (x)

(e)
for x in [1,2,3,4,5] :
    print (x)

(f)
for p in range(1, 10) :
    print (p)

(g)
for z in range (-500, 500, 100) :
    print (z)

(h)
x = 10
y = 5
for i in range (x - y * 2) :
    print ("%", i)
    
(i)
c = 0
for x in range (10) :
    for y in range (5) :
        c += 1
print (c)

(j)
x = [1,2,3]
counter = 0
while counter < len(x) :
    print(x [counter] * '%' )
    for y in x :
        print(y *'* ')
    counter += 1

(k)
for x in 'lamp' :
    print(str.upper(x))

(l)
x = 'one'
y = 'two'
counter = 0
while counter < len(x) :
    print ( x[counter], y[counter])
    counter += 1

(m)
x = "apple, pear, peach"
y = x.split(", ")
for z in y :
    print(z)

(n)
x = 'apple, pear, peach, grapefruit'
y = x. split(', ' )
for z in y :
    if z < 'm' :
        print(str.lower(z))
    else :
        print(str.upper(z))








Q3. Find and write the output of the following python code:

for Name in ['Jayes', 'Ramya', 'Taruna', 'Suraj'] :
    print (Name)
    if Name[0] == 'T' :
        break
    else :
        print("Finished!")
print ('Got it!')









Q4. How many times will the following for loop execute and what's the output?

(i)
for i in range(-1, 7, -2) :
    for j in range (3) :
        print(1, j)

(ii)
for i in range (1, 3, 1) :
    for j in range (i+1) :
        print('*')








Q5. Is the loop in the code below infinite? How do you know (for sure) before you run it?

m = 3
n = 5
while n < 10 :
    m = n - 1
    n = 2 * n - m

    print(n, m)




11 Comments

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

  1. Thank you so much for uploading all this content for CS students. Very very grateful.

    ReplyDelete
  2. WAP to create a binary file employee.bin containing records in the file - I'd, name, department, designation, salary. Perform read, write, search, delete and update operations in the file.

    ReplyDelete
  3. Replies
    1. Click on Question to get Answer of That question.

      Delete
  4. Sirf 5 questions hi h?

    ReplyDelete
  5. There are 6 questions

    ReplyDelete

Post a Comment

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

Previous Post Next Post