0% found this document useful (0 votes)
28 views

Python Worksheet For

Uploaded by

maiehabsaad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Python Worksheet For

Uploaded by

maiehabsaad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

AY 2023-2024

Subject: Computing Practical Worksheet

Name: ______Mai Ehab____Year: 8 Section: _B___ Date: _________________

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!")

2. # Display the cube of the number up to a given integer


input_number = 6
for i in range(1, input_number + 1):
print("Current Number is :", i, " and the cube is", (i * i * i))

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

5. # Python program to print odd Numbers in a List


# list of numbers
list1 = [10, 21, 4, 45, 66, 93]
# iterating each number in list
for num in list1:
# checking condition
if num % 2 != 0:
print(num, end = " ")

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)

7. # Python program to print odd Numbers in a List

# list of numbers
list1 = [10, 21, 4, 45, 66, 93]
i=0

# using while loop

Page 4
while(i < len(list1)):

# checking condition
if list1[i] % 2 != 0:
print(list1[i], end = " ")

# increment i
i += 1

8. # Python program to print Even Numbers in given range


# iterating each number in list
start=1
end=9
for num in range(start, end + 1):
# checking condition
if num % 2 == 0:
print(num, end = " ")

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

You might also like