The document contains examples of Python for loops and while loops to print numbers, letters, odd/even numbers, multiplication tables, and check for prime numbers. Loops are used to iterate through ranges and test conditions.
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 ratings0% found this document useful (0 votes)
8 views
Python Program
The document contains examples of Python for loops and while loops to print numbers, letters, odd/even numbers, multiplication tables, and check for prime numbers. Loops are used to iterate through ranges and test conditions.
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/ 5
1.
print the sum of n nos
n=int(input("enter the number:"))
s=0 for i in range(1,n+1,1): s=s+i print("sum",s)
2. print the alphabets in name
letter = "ANCHAL" for n in letter: print(n) else: print("i am in else")
3. #print odd numbers
n = int(input("Enter the limit")) for a in range(1,n+1,2): print(a) 4. #print even numbers n = int(input("Enter the limit")) for a in range(2,n+1,2): print(a)
5.#print multiplication table
n = int(input("Enter the limit")) for a in range(4,n+1,4): print(a)
6. #print numbers in reverse
n = int(input("Enter the limit"))
for n in range(n,0,-1):
print(n) 7. #check if a no is prime
n = int(input("Enter the number"))
for i in range(2,n,1): if n%i == 0: print(n,"is not a prime") break else: print(n,"is a prime")
8 #print odd nos
n = int(input("Enter the number")) a=1 while a<=n: print(a) a= a+2
#print even nos
n = int(input("Enter the number")) a=2 while a<=n: print(a) a= a+2