Page 5 - IPP-11
P. 5
(b) Write a Python program to find the largest of the three numbers. (3)
Or
Write a Python program to find the area and perimeter of a rectangle based on user choice. (If user types
1, area is displayed and if 2 is typed, perimeter is displayed.)
Ans. a = int(input("Enter 1st number:"))
b = int(input("Enter 2nd number:"))
c = int(input("Enter 3rd number:"))
if a>b and a>c:
print(a, 'is the largest number')
elif b>c:
print(b, 'is largest number')
else:
print(c, 'is largest number')
Or
l = int(input('Enter the length:'))
b = int(input('Enter the breadth:'))
choice = int(input('Enter your choice as 1 for area or 2 for perimeter:'))
if choice==1:
print('Area:', l*b)
elif choice==2:
print('Perimeter:',2*(l+b))
else:
print('Wrong choice')
(c) Convert the following Python program using for loop. (2)
i = 0
sum = 0
while i<=10:
sum = sum + i
i = i + 1
print(sum)
Ans. sum = 0
for i in range(1,11):
sum = sum + i
print(sum)
(d) Write a Python program to print the series 1 3 5 7 9 11 up to a given limit. (3)
Or
Write a Python program to find the product of numbers up to a given limit.
Ans. limit = int(input('Enter the limit:'))
for i in range(1,limit+1,2):
print(i,end=' ')
Or
prod = 1
limit = int(input('Enter the limit:'))
for i in range(1,limit+1):
prod = prod * i
print(prod)
2