Q. 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))



Answer =


(a)

Output:-

Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello
Hello

>>>

(b)

Output: -

10 0
9 1
8 2
7 3
6 4

>>>

(c)

Output: -

100
90
80
70
60
50

>>>

(d)

Output: -

45
45
45
45
45
45
45
45
45 infinite times.
>>>

(e)

Output: -

1
2
3
4
5

>>>

(f)

Output: -

1
2
3
4
5
6
7
8
9

>>>

(g)

Output: -

-500
-400
-300
-200
-100
0
100
200
300
400

>>>

(h)

It will give no output because the precedence of the * operator is more than the - operator.

So for value in the range becomes zero after solving.

(i)
Output: -

50
>>>

(j)

%
*
* *
* * *
%%
*
* *
* * *
%%%
*
* *
* * *

>>>

(k)

L
A
M
P

>>>

(l)

o t
n w
e o

>>>

(m)

apple
pear
peach

>>>

(n)

apple
PEAR
PEACH
grapefruit

>>>

10 Comments

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

  1. i need the video solution of the (j) part
    .......please provide me

    ReplyDelete
  2. I also want video solution for make me understand better.

    ReplyDelete
    Replies
    1. Sorry, it is not possible to make videos on each question. But don't worry I will try to upload solutions of this question.

      Delete
  3. what does split() do?

    ReplyDelete
  4. very useful for me it was very good for cs students can you make youtbe channel for cs

    ReplyDelete

Post a Comment

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

Previous Post Next Post