DS010923 - Practice Question Based on For Loops

1. Python Program for Sum of squares of first n natural numbers
2. Python Program for cube sum of first n natural numbers
3. Write a Python program which iterates the integers from 1 to 50. For multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
4.Write a program to display the first 7 multiples of 7.
5.Write a program to print multiplication table of a given number.
6.Write a Python Program which will return sum of all Even numbers between two Numbers.
7.Write a Python Program which will return sum of all odd numbers between two Numbers.
8. Write a program to display all the numbers which are divisible by 11 but not by 2
between 100 and 500.

5 Likes

1. Python Program for Sum of squares of first n natural numbers
n=int(input("enter the value: "))
sum=0
for i in range(1,n+1):
sum=sum+(i**2)
print(sum)

2. Python Program for cube sum of first n natural numbers
n=int(input("enter the value: "))
sum=0
for i in range(1,n+1):
sum=sum+(i**3)
print(sum)

3. Write a Python program which iterates the integers from 1 to 50. For multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
for i in range(1,51):
if (i%3==0 and i%5==0):
print(“FizzBuzz”)
elif i%3==0:
print(“Fizz”)
elif(i%5==0):
print(“Buzz”)
else:
print(i)

4.Write a program to display the first 7 multiples of 7.
for i in range(1,50):
if i%7==0:
print(i)
5.Write a program to print multiplication table of a given number.
n=int(input(“Enter the Number: “))
for i in range(1,11):
m=(ni)
print(n,"
”,i,”=",m)

O/P=Enter the Number: 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

6.Write a Python Program which will return sum of all Even numbers between two Numbers.
n=int(input("Enter the start range: "))
m=int(input("Enter the end range: "))
sum=0
for i in range(n,m):
if (i%2==0):
sum=sum+i
print(sum)

7.Write a Python Program which will return sum of all odd numbers between two Numbers.
n=int(input("Enter the start range: "))
m=int(input("Enter the end range: "))
sum=0
for i in range(n,m):
if (i%2!=0):
sum=sum+i
print(sum)

8. Write a program to display all the numbers which are divisible by 11 but not by 2
between 100 and 500.
for i in range(100,500):
if i%11==0 and i%2!=0:
print(i)

#1. Python Program for Sum of squares of first n natural numbers.

num=int(input("Enter your number : "))
sum=0
for i in range(1,num+1):
sum=sum+(i**2)
print("The Sum of Square is : ", sum)

#2. Python Program for cube sum of first n natural numbers.

num=int(input("Enter your number : "))
sum=0
for i in range(1,num+1):
sum=sum+(i**3)
print("The Sum of Cube is : ", sum)

#3. Write a Python program which iterates the integers from 1 to 50. For multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

for i in range(1,51):
if(i%3==0 and i%5==0):
print(“FizzBuzz”)
elif(i%5==0):
print(“buzz”)
elif(i%3==0):
print(“Fizz”)

#4.Write a program to display the first 7 multiples of 7.
count = 0
for i in range(1,100):
if(i%7==0):
print(i)
count+=1
if(count==7):
break

#5.Write a program to print multiplication table of a given number.

num=int(input("Enter Your Number : ",))
for i in range(1,11):
print(num, "" ,i, “=”, numi)

#6.Write a Python Program which will return sum of all Even numbers between two Numbers.

num1 = int(input("Enter Your First Number : ",))
num2 = int(input("Enter Your Second Number : ",))
sum = 0
for i in range(num1,num2+1):
if(i%2==0):
sum=sum+i
print(“Sum of Even Number between”, num1, “and”, num2, “is”, sum)

#7.Write a Python Program which will return sum of all odd numbers between two Numbers.

num1 = int(input("Enter Your First Number : ",))
num2 = int(input("Enter Your Second Number : ",))
sum = 0
for i in range(num1,num2+1):
if(i%2!=0):
sum=sum+i
print(“Sum of Odd Number between”, num1, “and”, num2, “is”, sum)

#8. Write a program to display all the numbers which are divisible by 11 but not by 2 between 100 and 500.

for i in range(100,501):
if(i%11==0 and i%2!=0):
print(i)

Q-1. Python Program for Sum of squares of first n natural numbers

Number = int(input(“Enter your first n natural number :”))
Sum = 0
for i in range(0,Number+1):
Sum = Sum + i**2
print(“Sum of square of given natural number is :”,Sum)

#Q-2. Python Program for cube sum of first n natural numbers

Number = int(input("Enter your n natural number : "))
Sum = 0
for i in range(0,Number+1):
Sum = Sum + i**3
print(“Sum of cube of given natural number is :”,Sum)

#Q-3. Write a Python program which iterates the integers from 1 to 50. For multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

for i in range(1,51):
if i%3 == 0 and i%5 == 0:
print(“FIZZBUZZ”)
elif i%3 == 0:
print(“FIZZ”)
elif i%5 == 0:
print(‘BUZZ’)
else:
print(i)

#Q-4.Write a program to display the first 7 multiples of 7

for i in range(1,8):
Number = i*7
print(Number)

#Q-5.Write a program to print multiplication table of a given number.

Number = int(input(“Enter your number :”))
for i in range(1,11):
Table = Number*i
print(Table)

# Q-6.Write a Python Program which will return sum of all Even numbers between two Numbers.

Num1 = int(input(“Enter your first number :”))
Num2 = int(input(“Enter your second number :”))
Sum = 0
for i in range(Num1,Num2+1):
if i%2 == 0:
Sum = Sum+i
print(Sum)

#Q-7.Write a Python Program which will return sum of all odd numbers between two Numbers.

Num1 = int(input(“Enter your first number :”))
Num2 = int(input(“Enter your second number :”))
Sum = 0
for i in range(Num1,Num2+1):
if i%2 != 0:
Sum = Sum+i
print(Sum)

Q-8. Write a program to display all the numbers which are divisible by 11 but not by 2

between 100 and 500.

for i in range(100,500):
if i%11 == 0 and i%2 != 0:
print(i)

1. Python Program for Sum of squares of first n natural numbers

n= int(input("Enter the natural number: "))
sum=0
for i in range(1,n+1):
sum=sum+i**2
print(sum)

2. Python Program for cube sum of first n natural numbers

n= int(input("Enter the natural number: "))
sum=0
for i in range(1,n+1):
sum=sum+i**3
print(sum)

3. Write a Python program which iterates the integers from 1 to 50. For multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

for i in range (1,51):
if i%3==0 and i%5==0:
print(“Fizzbuzz”)
elif i%3==0:
print(“Fizz”)
elif i%5==0:
print(“Buzz”)
else:
print(i)

4.Write a program to display the first 7 multiples of 7.

num=7
for i in range(1,8):
multiple=num*i
print("first 7 multiples of 7 is: ",multiple)

5.Write a program to print multiplication table of a given number.

num=int(input("Enter a number: "))
for i in range(1,11):
multiple=num*i
print(multiple)

6.Write a Python Program which will return sum of all Even numbers between two Numbers.

start = int(input("Enter the starting number: "))
end = int(input("Enter the ending number: "))
sum = 0
for i in range(start,end+1):
if i%2==0:
sum=sum+i
print(sum)

7.Write a Python Program which will return sum of all odd numbers between two Numbers.

start = int(input("Enter the starting number: "))
end = int(input("Enter the ending number: "))
sum = 0
for i in range(start,end+1):
if i%2!=0:
sum=sum+i
print(sum)

8. Write a program to display all the numbers which are divisible by 11 but not by 2
between 100 and 500.

for i in range(100,501):
if i%11==0 and i%2!=0:
print(i)

1. Python Program for Sum of squares of first n natural numbers

n= int(input("Enter the natural number: "))
sum=0
for i in range(1,n+1):
sum=sum+i**2
print(sum)

2. Python Program for cube sum of first n natural numbers

n= int(input("Enter the natural number: "))
sum=0
for i in range(1,n+1):
sum=sum+i**3
print(sum)

3. Write a Python program which iterates the integers from 1 to 50. For multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

for i in range (1,51):
if i%3==0 and i%5==0:
print(“Fizzbuzz”)
elif i%3==0:
print(“Fizz”)
elif i%5==0:
print(“Buzz”)
else:
print(i)
.Write a program to display the first 7 multiples of 7.

num=7
for i in range(1,8):
multiple=num*i
print("first 7 multiples of 7 is: ",multiple)

5.Write a program to print multiplication table of a given number.

num=int(input("Enter a number: "))
for i in range(1,11):
multiple=num*i
print(multiple)6.Write a Python Program which will return sum of all Even numbers between two Numbers.

start = int(input("Enter the starting number: "))
end = int(input("Enter the ending number: "))
sum = 0
for i in range(start,end+1):
if i%2==0:
sum=sum+i
print(sum)

7.Write a Python Program which will return sum of all odd numbers between two Numbers.

start = int(input("Enter the starting number: "))
end = int(input("Enter the ending number: "))
sum = 0
for i in range(start,end+1):if i%2!=0:
sum=sum+i
print(sum)

  1. Write a program to display all the numbers which are divisible by 11 but not by 2
    between 100 and 500.

for i in range(100,501):
if i%11==0 and i%2!=0:
print(i)

1. Python Program for Sum of squares of first n natural numbers
n = int(input(“Enter a integer”))
squares_sum = 0
for i in range(1, n + 1):
squares_sum += i ** 2

print(“The sum of squares of the natural numbers is”,squares_sum)

2)Python Program for cube sum of first n natural numbers

n = int(input(“Enter a integer”))
cubes_sum = 0
for i in range(1, n + 1):
cubes_sum += i ** 3

print(“The sum of cubes of the natural numbers is”,cubes_sum)

3)Write a Python program which iterates the integers from 1 to 50.
**For multiples of three print “Fizz” instead of the number and for the multiples of five **
print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
for num in range(1, 51):
if num % 3 == 0 and num % 5 == 0:
print(“FizzBuzz”)
elif num % 3 == 0:
print(“Fizz”)
elif num % 5 == 0:
print(“Buzz”)
else:
print(num)

4)Write a program to display the first 7 multiples of 7.
for i in range(1, 8):
table = 7 * i
print(table)

5)Write a program to print multiplication table of a given number.

number = int(input(“Enter a number”))

for i in range(1, 11):
table = number * i
print(table)

6)Write a Python Program which will return sum of all Even numbers between two Numbers.
start = int(input(“Enter the starting number”))
end = int(input(“Enter the ending number”))

sum= 0
for num in range(start, end + 1):
if num % 2 == 0:
sum += num
print(sum)

7)Write a Python Program which will return sum of all odd numbers between two Numbers.
start = int(input(“enter a starting number”))
end= int(input(“enter a ending number”))

sum=0
for num in range (start,end+1):
if num % 2 != 0:
sum += num
print(sum)

8)Write a program to display all the numbers which are divisible by 11 but not by 2
between 100 and 500.

for num in range(100, 501):
if num % 11 == 0 and num % 2 != 0:
print(num)

Python Program for sum of squares of first n natural numbers

n = int(input(“Enter the natural number”))
sum=0
for i in range(1,n+1):
sum=sum+i**2
print(sum)

Python Program for cube sum of first n natural numbers

n= int(input(“Enter the natural number”))
sum=0
for i in range(1,n+1):
sum=sum+i**3
print(sum)

Python Program which iterates the integers from 1 to 50

For multiples of three print “Fizz” instead of the number and

for the multiples of five print “Buzz”.

For numbers which are multiples of both three and five print “FizzBuzz”.

for i in range(1,51):
if i%3==0 and i%5==0:
print(“FizzBuzz”)
elif i%3==0:
print(“Fizz”)
elif i%5==0:
print(“Buzz”)
else:
print(i)

Write a program to display the first 7 multiples of 7.

num=7
for i in range(1,8):
multiple=num*i
print(multiple)

#Write a program to print multiplication table of a given number.

num=int(input(“Enter a Number:”))
for i in range(1,11):
multiple=numi
print(num,"
“,i,”=",multiple)

#Write a Python Program which will return sum of all Even numbers between two Numbers.
start=int(input(“Enterthe starting number”))
end=int(input(“Enter the ending number”))
sum=0
for i in range(start,end+1):
if i%2==0:
sum=sum+i
print(sum)

Write a Python Program which will return sum of all odd numbers between two Numbers.

start= int(input(“Enter the starting number”))
end= int(input(“Enter the ending number”))
sum=0
for i in range(start,end+1):
if i%2!=0:
sum=sum+i
print(sum)

Write a program to display all the numbers which are divisible by 11 but

not by 2 between 100 and 500.

for i in range(100,501):
if i%11==0 and i%2!=0:
print(i)

#1. Python Program for Sum of squares of first n natural numbers

n=int(input(“Enter the number:”))
sum=0
for i in range(1,n+1):
sum+=(i**2)
print(“The sum of squares of first”, n, “natural numbers is”, sum)

#2. Python Program for cube sum of first n natural numbers

n=int(input(“Enter the number:”))
sum=0
for i in range(1,n+1):
sum+=(i**3)
print(“The sum of Cube of first”, n, “natural numbers is”, sum)

#3. Write a Python program which iterates the integers from 1 to 50. For multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

for i in range(1,51):
if i%5==0 and i%3==0:
print(“FizzBUZZ”)
elif i%3==0:
print(“Fizz”)
elif i%5==0:
print(“Buzz”)
else:
print(i)

#4.Write a program to display the first 7 multiples of 7.
for i in range(1,50):
if i%7==0:
print(i)

#5.Write a program to print multiplication table of a given number.

n=int(input(“Enter the number:”))
for i in range(1,11):
m=n*i
print(m)

#6.Write a Python Program which will return sum of all Even numbers between two Numbers.
num1=int(input(“Enter the number:”))
num2=int(input(“Enter the number:”))
sum=0
for i in range(num1,num2+1):
if i%2==0:
sum=sum+i
print(sum)
#7.Write a Python Program which will return sum of all odd numbers between two Numbers.

num1=int(input(“Enter the number:”))
num2=int(input(“Enter the number:”))
sum=0
for i in range(num1,num2+1):
if i%2!=0:
sum=sum+i
print(sum)

#8. Write a program to display all the numbers which are divisible by 11 but not by 2 between 100 and 500.

for i in range(100,501):
if i%11==0 and i%2!=0:
print(i)

1. Python Program for Sum of squares of first n natural numbers.

num = int(input(‘enter the number:’))
sum=0
for i in range(num+1):
sum = sum+ (i**2)
print(sum)

2. Python Program for cube sum of first n natural numbers.
num = int(input(‘enter the number:’))
sum=0
for i in range(num+1):
sum = sum+ (i**3)
print(sum)

**3. Write a Python program which iterates the integers from 1 to 50. For multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

for i in range(1,51):
if i%3 == 0:
print(‘FIzz’)
elif i%5 == 0:
print(‘Buzz’)
elif i%3==0 and i%5==0:
print(‘FizzBuzz’)

4.Write a program to display the first 7 multiples of 7.

num = int(input(‘enter the number:’))
for i in range(1,(num*7)+1):
if i%7==0:
print(i)

5.*Write a program to print multiplication table of a given number.
num = int(input(‘enter the number:’))

for i in range(1, 11):
sum = num* i
print(num,‘*’,i,‘=’,sum)

6.Write a Python Program which will return sum of all Even numbers between two Numbers.
start = int(input(‘enter start value:’))
end = int(input(‘enter second value:’))
sum=0
for i in range(start , end+1):
if i%2==0:
sum =sum+i
print(sum)
7.Write a Python Program which will return sum of all odd numbers between two Numbers.

start = int(input(‘enter the starting number:’))
end = int(input(‘enter the end number:’))
sum =0
for i in range(start , end+1):
if i%2 !=0:
sum = sum +i
print(sum)

8. Write a program to display all the numbers which are divisible by 11 but not by 2
between 100 and 500.
for i in range(100,500):
if i%11 == 0 and i%2 != 0 :
print(i)

#1.Write a program to print numbers from 1 to 20 except multiple of 2 & 3. using while loop.

i = 1
while i < 21:
if i % 2 != 0 and i%3 != 0:
print(i)
i = i + 1

#2. Write a Python Program for Sum of squares of first n natural numbers Using While Loop
start_value = int(input(“enter first number”))
end_value = int(input(“enter last value”))

sum = 0
i = start_value
while i <= end_value:
sum = sum + (i*i)
print(sum)
i = i + 1

#3. Write a program to print multiplication table of a given number using while loop

num = int(input(“enter which table you want”))

i = 1
while i < 11:
mult = i * num
print(mult)
i = i + 1

#4. Write a Python Program which will return sum of all Even numbers between two Numbers by while loop.

first_num = int(input(“enter first num”))
last_num = int(input(“enter last num”))

sum = 0
i = first_num
while i <= last_num:
if i%2 == 0:
sum = sum + i
print(sum)
i = i + 1

#5.Write a Python Program which will return sum of the numbers between a given range using While Loop.

first_num = int(input(“enter first number”))
end_num = int(input(“enter end number”))

sum = 0
i = first_num
while i <= end_num:
sum = sum+i
print(sum)
i = i + 1

FOR LOOP QUESTIONS:

#1. Python Program for Sum of squares of first n natural numbers

first_num= int(input(“enter first num”))
end_num = int(input(“enter end num”))
sum = 0
for i in range(first_num, end_num + 1):
sum = sum + (i*i)
print(sum)

#2. Python Program for Sum of cubes of first n natural numbers

num = int(input(“enter a num”))
sum = 0
for i in range(1, num+1):
sum = sum + (iii)
print(sum)

#3. Write a Python program which iterates the integers from 1 to 50. For multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

for i in range(1,51):
if i%3 == 0:
print(“Fizz”)
elif i%5 == 0:
print(“Buzz”)
elif i%3 and i%5 == 0:
print(“FizzBuzz”)
else:
print(“invalid”)

#4.Write a program to display the first 7 multiples of 7

for i in range(1,50):
if i%7 == 0:
print(i)

#5.Write a program to print multiplication table of a given number.

num = int(input(“enter which table you want”))
for i in range(1,11):
table = i * num
print(table)

#6.Write a Python Program which will return sum of all Even numbers between two Numbers.

first_num = int(input(“enter first number”))
end_num = int(input(“enter last number”))
sum = 0
for i in range(first_num, end_num + 1):
if i%2 == 0:
sum = sum + i
print(sum)

#7.Write a Python Program which will return sum of all odd numbers between two Numbers

first_num = int(input(“enter first num”))
end_num = int(input(“enter end num”))

sum = 0
for i in range(first_num, end_num+1):
if i%2 != 0:
sum = sum + i
print(sum)