Sharpen Your Skills: Programming Languages Practice Q&A

Programming practice questions

for, while loop in Python Language

 
1

Question- How to print 1 to 30 in Python Language?



Answer- for a in range(1,31):
                 print(a)
2

Question- How to print 30 to 1 in Python Language?



Answer- for a in range(30,1,-1):
            print(a)
3

Question- How to print all odd number between 1 to 50 in Python Language?



Answer- for a in range(1,51,2):
                         print(a)


or

for a in range(1,51):
                if(a%2!=0):
                           print(a)
4

Question- How to print factorial of any given number in Python Language?



Answer- num=int(input("Enter a number"))
f=1
for a in range(1,num+1):
                      f=f*a
print("Factorial of given number ", num, "is :", f)