Loops?
Loops?
Grade 6
print(i)
for i in range(5):
print('Hello')
print(i)
print(i * i)
print(fruit)
print(i)
total = 0
total += i
print(total)
print(i)
for ch in 'loop':
print(ch)
Grade 7
if i % 2 != 0:
print(i)
print(i)
total = 0
total += i
print(total)
i = 1
while i <= 5:
print(i)
Python Loop Coding Tasks with Solutions (Grade 6 to 9)
i += 1
print(i)
for ch in 'education':
if ch in 'aeiou':
print(ch)
nums = [1,2,3,4,5]
for i in reversed(nums):
print(i)
if i % 2 == 0:
print(i)
for ch in 'robot':
print(ch)
Grade 8
print('*' * i)
word = 'python'
rev = ''
for ch in word:
rev = ch + rev
Python Loop Coding Tasks with Solutions (Grade 6 to 9)
print(rev)
print(i)
Task: Factorial of 5
n = 5
fact = 1
fact *= i
print(fact)
name = 'Zahid'
for ch in name:
print(ch)
count = 0
for ch in 'robotics':
if ch in 'aeiou':
count += 1
print(count)
import math
for i in range(1,6):
print(math.sqrt(i))
text = 'code'
for ch in text:
print(ch.upper())
total = 0
total += i
print(total)
Grade 9
print(i*j, end='\t')
print()
num = 7
is_prime = True
if num % i == 0:
is_prime = False
break
num = 123
total = 0
total += num % 10
num //= 10
print(total)
Python Loop Coding Tasks with Solutions (Grade 6 to 9)
for i in range(5):
print(x)
if i % 3 == 0 and i % 5 == 0:
print(i)
fact = 1
fact *= i
print(fact)
s = 'madam'
if s == s[::-1]:
print('Palindrome')
else:
print('Not Palindrome')
a, b = 0, 1
for i in range(10):
print(a)
a, b = b, a + b
for ch in 'python':
print(ch, ord(ch))
if num % i == 0:
break
else:
print(num)