Python3 exercise with solutions (Set 2)
Problem 1: To print n odd numbers. Solution n=int(input("Enter number:")) i=0 for i in range(n+1): if(i%2!=0): print (i) Output Enter number:7 1 3 5 7 Problem 2: To find the sum of digits of the given number. Solution n=int(input ("Enter number")) sum=0 while(n>0): d=n%10 n=n//10 sum=sum+d print (sum) Output Enter number:345 12 Problem 3: To print the given pattern. 1 1 3 1 3 5 1 3 5 7 Solution n=int(input("Enter number")) i=0 j=0 for i in range (0,n+1): for j in range (0,i+1): k=(2*j)+1 print (k) print ("/n") Output Enter number:4 1 1 3 1 3 5 1 3 5 7 Problem 4: To check whether the given number is an amstrong number or not.(eg.153=(1*1*1)+(5*5*5)+(3*3*3)=153 Solution n=int(input ("Enter number")) sum=0 x=n while (n>0): d=n%10 n=n//10 cube=d*d*d sum=sum+cube print (sum) if(x==sum): print ("Amstrong number") else: print ("Not an amst