Python Worksheet For
Python Worksheet For
Learning Objectives:
Analyse the time complexity of algorithms involving count-controlled iteration
Unit: Python Programming Topic: Count Controlled iteration
Debug the code and paste the screenshot next to the code.
1. #Display a message “Done” after successful execution of for loop
for i in range(5):
print(i)
else:
print("Done!")
Page 1
3. #Reverse a given integer number
num = 76542
reverse_number =
print("Given Number ", num)
while num > 0:
reminder = num % 10
reverse_number = (reverse_number * 10) + reminder
num = num // 10
print("Revered Number ", reverse_number)
Page 2
4. #print capitals names
city = ['Tokyo','New York','Toronto','Hong Kong']
print('Cities loop:')
for x in city:
print('City: ' + x)
print('\n') # newline
Page 3
6. # Print First 10 natural numbers using for loop
x = (1,2,3,4,5,6,7,8,9,10)
for i in x:
print(i)
# list of numbers
list1 = [10, 21, 4, 45, 66, 93]
i=0
Page 4
while(i < len(list1)):
# checking condition
if list1[i] % 2 != 0:
print(list1[i], end = " ")
# increment i
i += 1
Page 5
9. #Multiple of2
num = [1,2,3,4,5,6,7,8,9]
print('x^2 loop:')
for x in num:
y=x*x
print(str(x) + '*' + str(x) + '=' + str(y))
Page 6