0% found this document useful (0 votes)
6 views7 pages

Loops?

The document provides a series of Python loop coding tasks and their solutions, categorized by grade levels from 6 to 9. Each grade includes various tasks such as printing numbers, calculating sums, generating multiplication tables, and checking for prime numbers. The tasks are designed to help students practice and enhance their programming skills using loops in Python.

Uploaded by

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

Loops?

The document provides a series of Python loop coding tasks and their solutions, categorized by grade levels from 6 to 9. Each grade includes various tasks such as printing numbers, calculating sums, generating multiplication tables, and checking for prime numbers. The tasks are designed to help students practice and enhance their programming skills using loops in Python.

Uploaded by

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

Python Loop Coding Tasks with Solutions (Grade 6 to 9)

Python Loop Coding Tasks with Solutions

Grade 6

Task: Print numbers from 1 to 10

for i in range(1, 11):

print(i)

Task: Print 'Hello' five times

for i in range(5):

print('Hello')

Task: Print first 5 even numbers

for i in range(2, 11, 2):

print(i)

Task: Print squares of numbers from 1 to 5

for i in range(1, 6):

print(i * i)

Task: Print each fruit from list

fruits = ['apple', 'banana', 'cherry']

for fruit in fruits:

print(fruit)

Task: Print numbers from 5 to 1

for i in range(5, 0, -1):

print(i)

Task: Print multiplication table of 2

for i in range(1, 11):

print('2 x', i, '=', 2*i)

Task: Sum of numbers 1 to 5

total = 0

for i in range(1, 6):


Python Loop Coding Tasks with Solutions (Grade 6 to 9)

total += i

print(total)

Task: Print first 5 odd numbers

for i in range(1, 10, 2):

print(i)

Task: Print characters in 'loop'

for ch in 'loop':

print(ch)

Grade 7

Task: Print all odd numbers from 1 to 10

for i in range(1, 11):

if i % 2 != 0:

print(i)

Task: Countdown from 10 to 1

for i in range(10, 0, -1):

print(i)

Task: Multiplication table of 3

for i in range(1, 11):

print('3 x', i, '=', 3 * i)

Task: Sum of first 10 natural numbers

total = 0

for i in range(1, 11):

total += i

print(total)

Task: Print numbers 1 to 5 using while loop

i = 1

while i <= 5:

print(i)
Python Loop Coding Tasks with Solutions (Grade 6 to 9)

i += 1

Task: Print multiples of 4 up to 40

for i in range(4, 41, 4):

print(i)

Task: Print all vowels in 'education'

for ch in 'education':

if ch in 'aeiou':

print(ch)

Task: Print reverse of list [1,2,3,4,5]

nums = [1,2,3,4,5]

for i in reversed(nums):

print(i)

Task: Print even numbers from 20 to 30

for i in range(20, 31):

if i % 2 == 0:

print(i)

Task: Print each letter of 'robot'

for ch in 'robot':

print(ch)

Grade 8

Task: Print star pattern

for i in range(1, 6):

print('*' * i)

Task: Reverse 'python'

word = 'python'

rev = ''

for ch in word:

rev = ch + rev
Python Loop Coding Tasks with Solutions (Grade 6 to 9)

print(rev)

Task: Print even numbers from 1 to 20

for i in range(2, 21, 2):

print(i)

Task: Factorial of 5

n = 5

fact = 1

for i in range(1, n+1):

fact *= i

print(fact)

Task: Print each character of your name

name = 'Zahid'

for ch in name:

print(ch)

Task: Count vowels in 'robotics'

count = 0

for ch in 'robotics':

if ch in 'aeiou':

count += 1

print(count)

Task: Print square roots of numbers 1-5

import math

for i in range(1,6):

print(math.sqrt(i))

Task: Print multiplication table of 7

for i in range(1, 11):

print('7 x', i, '=', 7*i)

Task: Print all letters in uppercase


Python Loop Coding Tasks with Solutions (Grade 6 to 9)

text = 'code'

for ch in text:

print(ch.upper())

Task: Sum of even numbers 1 to 10

total = 0

for i in range(2, 11, 2):

total += i

print(total)

Grade 9

Task: Multiplication table from 1 to 5

for i in range(1, 6):

for j in range(1, 6):

print(i*j, end='\t')

print()

Task: Check if 7 is prime

num = 7

is_prime = True

for i in range(2, num):

if num % i == 0:

is_prime = False

break

print('Prime' if is_prime else 'Not Prime')

Task: Sum of digits of 123

num = 123

total = 0

while num > 0:

total += num % 10

num //= 10

print(total)
Python Loop Coding Tasks with Solutions (Grade 6 to 9)

Task: Take 5 inputs from user

for i in range(5):

x = input('Enter input: ')

print(x)

Task: Print numbers divisible by 3 and 5 (1 to 50)

for i in range(1, 51):

if i % 3 == 0 and i % 5 == 0:

print(i)

Task: Find factorial of a number entered by user

n = int(input('Enter number: '))

fact = 1

for i in range(1, n+1):

fact *= i

print(fact)

Task: Check if string is palindrome

s = 'madam'

if s == s[::-1]:

print('Palindrome')

else:

print('Not Palindrome')

Task: Print Fibonacci series up to 10 terms

a, b = 0, 1

for i in range(10):

print(a)

a, b = b, a + b

Task: Print ASCII of each character in 'python'

for ch in 'python':

print(ch, ord(ch))

Task: Print all prime numbers from 1 to 20


Python Loop Coding Tasks with Solutions (Grade 6 to 9)

for num in range(2, 21):

for i in range(2, num):

if num % i == 0:

break

else:

print(num)

You might also like