Python Program Examples (1)
Python Program Examples (1)
i=1
while i<=10:
i+=1
2. examples of while loops in Python for Printing those numbers divisible by either 5 or 7 within 1 to
50 using a while loop.
i=1
while i<51:
if i%5 == 0 or i%7==0 :
i+=1
3. while loops in Python, the sum of squares of the first 15 natural numbers using a while loop.
num = 15
summation = 0
c=1
4. use the while loop for printing the multiplication table of a given number.
num = 21
counter = 1
# we will use a while loop for iterating 10 times for the multiplication table
print("The Multiplication Table of: ", num)
For Loop
5.Write a program to input a number and display sum of all the digits of number.
res=0
for i in range(0,len(a)):
res=(res+int(a[i]))
print("Sum of digit Number is : ",res)
for i in range(1,a):
for j in range(2,i):
if(i%j==0):
flg=0
break
else:
flg=1
if(flg==1):
print("Not Prime")
else:
print("Prime")
7. Write a program to input a number and print whether number is Palindrom or not
while(n>0):
d=n%10
rev=rev*10+d
n=n//10
if(temp==rev):
w = ""
for i in x:
w=i+w
if (x==w):
print("String is Palindrome")
if(x!=w):