17.Sample Programs using-loops and nested loops
Sum of the digits of a number sum=0 n=int(input("Enter a number..")) while n!=0: sum=sum+n%10; n=n//10 print("Sum of the digits=",sum) Output: Enter a number..123 Sum of the digits=6 Write a Python program to reverse a number and also find the sum of the digits of a number(University Question) sum=0 n=int(input("Enter a number..")) rev=0 while n!=0: d=n%10 sum=sum+d rev=rev*10+d n=n//10 print("Sum of the digits=",sum) print("Reverse of the number=",rev) Output Enter a number..123 Sum of the digits= 6 Reverse of the number= 321 Program to check whether the given number is prime or not n=int(input("Enter a number..")) i=2 prime=True while i<=n//2: if n%i==0: prime=False break i=i+1 if prime==True: print('Prime number') e...