Previous Index Next

Review Questions

Short Answer

1. How many times will 'Hello World' be printed in the following program?

count = 1 
while count <= 10:
    print('Hello World')
    count = count + 3


2. What is wrong with this Python loop:

n = 10
while n > 0 :
    print(n)
print('All done')


3. What will the following code display?

sum = 0 
for count in range(1, 6): 
     sum = sum + count 
print(sum)


4. What will the following code display?

for number in range(6, 66, 6):
     print(number, end=' ')


5. What will the following code display?

for number in range(10, 5, -1):
    print(number)


6. Write the output of following code.

val = 10
total = 0

for count in range(1,val,3):
    total = total + count
    if count % 2 == 0:
        print(count*10)
    else:
        print(count)

print (total)


7. Write the output of following code.

num = 532
r = 0
while num > 0:
    digit = num % 10
    r = digit + r * 10
    num = num // 10
print(r)


8. Write the output of following code.

for i in range(1,6):
    for j in range(1,i+1):
        print("*",end='')
    print()


Programming Exercises

For Lab Programming Questions click here.

Previous Index Next