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.
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.
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