Assignment IP Looping, Funbda
Assignment IP Looping, Funbda
d= 18.25 to an integer
p= “89.5” to a float
m= 99
n= 21.85
What will be the datatype of print
(m+n)
ITERATION :
b) i=10
while (i>0):
print(“Value of i”,i)
else:
print (“Out of loop”)
c) i=10
while (i>0):
print(“Value of i”,i)
i-=3
else:
print (“Out of loop”)
3. Consider following three codes and display the output produced by these codes
a) i=0
while i <10:
i +=1
if i%2==0:
print(i)
b) i=0
while i >10:
i +=1
if i%2==0:
print(i)
c) i=0
while i<1:
i -=1
if i%2==0:
print(i)
4. Consider
i=0
while i <=10:
i +=1
2
if i%2==0:
print(i)
5. Make changes in the code so that it prints values less than 10 but not value 10, WITHOUT changing the
test condition of while loop.
6. Find the errors and correct the code:
a) i =10
While (i < 100) :
Print (a)
Print(“over!”)
b) key = ‘panda’
Correct = false
while not correct :
inp = input(“Enter secret key :”)
if inp == secret :
print (“CORRECT! You got that.”)
else :
print (“Wrong guess. Try again.”)
7. Find the syntactical errors in following codes. Underline the erroneous part and write corrected codes.
a) for iMus range (10)
B = 19 + iMus
Print (b)
b) while k < 10 :
print (k)
k = k+2
c) a = 5
While a < 10 : print (a *2)
Else print (a + 1)
d) For p in range(3)
for q in range(3)
Print (p * q)
else:
Print (“outer loop ends”)
e) for p in range(3)
for q in range(3)
Print (p * q)
elif:
print (“loop ends”)
else :
print (“loop over”)
8. How many times will the given loops iterate?
(a) j=0
while (j < 50):
print (“Hello World”)
(b) j = 25
while (25 <= j <= 30):
Print (“Temp variable =”, j)
J = j+1
(c) j = 25
while (25 <= j < 30):
Print (“Temp variable =”, j)
J = j+1
9. Write down the syntax of break and continue statement used in a ‘for’ loop.
Programming :
1. To print the first “n” multiples of a given no.
2. To calculate profit – loss for given cost and sell price.
3
3. To find sale price of an item with given cost and discount (%).
4. To find the sum of squares of the first 100 natural numbers.
5. Display Fibonacci series up to 10 terms
6. Find the factorial of a given number
7. Display numbers from -10 to -1 using for loop
8. Write a program to print multiplication table of a given number
9. Print First 10 natural numbers using while loop
10. Calculate the cube of all numbers from 1 to a given number
11. Find the sum of the series upto n terms
14 Accept three sides of a triangle and check whether it is an equilateral, isosceles or scalene
triangle?