Q. Trace the following code for these values of k and predict the output:


(i) k = 79
(ii) k = 29
(iii) k = 39
(iv) k = 59
(v) k = 30
(vi) k = 50
(vii) k = 60

Also write flow of execution for the given input.

k = int (input ("Enter Number :- "))
if (k > 50) :   #1
    if (k < 60) :   #2
        print ("One")   #3
    else:   #4
        print ("Two")   #5
else:   #6
    if (k > 30):    #7
        print ("Three") #8
    else:   #9
        print ("Four")  #10

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

Answer :-

For k's this value Output Flow-of-execution
(i) 79 Two 1 -> 2 -> 4 -> 5
(ii) 29 Four 1 -> 6 -> 7 -> 9 -> 10
(iii) 39 Three 1 -> 6 -> 7 -> 8
(iv) 59 One 1 -> 2 -> 3
(v) 30 Four 1 -> 6 -> 7 -> 9 -> 10
(vi) 50 Three 1 -> 6 -> 7 -> 8
(vii) 60 Two 1 -> 2 -> 4 -> 5

Post a Comment

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

Previous Post Next Post