Example program for Loop
Example program for Loop
n=eval(input("enter a"))
for i in range(1,n,1):
if(i%5==0 and i%10!=0):
print(i)
output
enter a:30
5
15
25
Fibonacci series
a=0
b=1
n=eval(input("Enter the number of terms: "))
print("Fibonacci Series: ")
print(a,b)
for i in range(1,n,1):
c=a+b
print(c)
a=b
b=c
output
Enter the number of terms: 6
Fibonacci Series:
01
1
2
3
5
8
Output
enter a number:10
1
2
5
10
output
enter a no:7
The num is a prime number.
Output
enter a number:6
the number is perfect number
Output
enter no of prime numbers to be
displayed:5
2
3
5
7
11
Program to print prime numbers in range
lower=eval(input("enter a lower range"))
upper=eval(input("enter a upper range"))
for n in range(lower,upper + 1):
if n > 1:
for i in range(2,n):
if (n % i) == 0:
break
else:
print(n)
output:
enter a lower range50
enter a upper range100
53
59
61
67
71
73
79
83
89
97