Python Lab Manual (22616)
Practical 5 : Write Python Program to demonstrate use of looping statements : 'While ' Loop ,'for' Loop, and Nested loop.
*Practical Related Questions.
1) 1. What would be the output from the following Python code segment?
x=10
while x>5:
print x,
x-=1
Ans=> SyntaxError: Missing parentheses in call to 'print'. Did you mean print(x, end=" ")?
2. Change the following Python code from using a while loop to for loop:
x=1
while x<10:
print x
x+=1
Ans=> for x in range(1,10)
print(x)
*Exercise
1) Print the following patterns using loop:
a. *
**
***
****
Ans =>
for j in range(0,i+1):
print("*",end="")
print("")
b.
*
***
*****
***
*
Ans =>
101010110101011010101
c.
1010101
10101
101
1
Ans =>
2. Write a Python program to print all even numbers between 1 to 100 using while
loop.
Ans =>
3. Write a Python program to find the sum of first 10 natural numbers using for loop.
Ans =>
4. Write a Python program to print Fibonacci series.
Ans =>
5. Write a Python program to calculate factorial of a number
Ans =>
6. Write a Python Program to Reverse a Given Number
Ans =>
7. Write a Python program takes in a number and finds the sum of digits in a
number.
Ans =>
8. Write a Python program that takes a number and checks whether it is a palindrome
or not
Ans =>
0 Comments