Page 182 - Information_Practice_Fliipbook_Class11
P. 182
j. print('Bye' == 'BYE')
Output: False
k. print(10 != 9 and 20 >= 20)
Output: True
l. print(10 + 6 * 2 ** 2 != 9//4 -3 and 29>= 29/9)
Output: True
m. print(5 % 10 + 10 < 50 and 29 <= 29)
Output: True
n. print((0 < 6) or (not(10 == 6) and (10<0)))
Output: True
5. Categorise the following as syntax error, logical error or runtime error:
a. 25 / 0
b. num1 = 25; num2 = 0; num1/num2
Ans. a. 25 / 0 :- Runtime Error, divisible by zero
b. num1 = 25; num2 = 0; num1/num2 :- Runtime Error, divisible by zero
6. Write a Python program to calculate the amount payable if money has been lent on simple interest. Principal or money lent = P, Rate =
R% per annum and Time = T years. Then Simple Interest (SI) = (P x R x T)/ 100.
Amount payable = Principal + SI.
P, R and T are given as input to the program.
Ans. principal = float(input('Enter Principal Amount: '))
rate = float(input('Enter Rate of Interest '))
time = float(input('Enter Time (in Years)'))
simpleInterest = (principal * rate * time) / 100
amountPayable = principal + simpleInterest
print('Total Payable amount', amountPayable)
7. Write a program to repeat the string "GOOD MORNING" n times. Here n is an integer entered by the user.
Ans. num = int(input("Enter Number of times the string is to be repeated: "))
print('String repeated', num, 'times is:')
print("GOOD MORNING"*num)
8. What is the difference between else and elif construct of if statement?
Ans.
else elif
else is a part of if statement. The elif is short for else if.
else statement is executed whenever the if statement elif executed block of code whenever one of the condition
is getting false. evaluate true.
Example: Example:
a = 10 num = -5
b = 20 if (num > 0):
if(a < b): print ("positive number")
print ("a less than b") elif (num == 0):
else: print zero")
print ("a is not less than b") else:
int ("negative number")
9. Write a program to find the average of 3 numbers.
Ans. num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
num3 = int(input("Enter Third Number: "))
print("Average=",(num1 + num2 + num3) / 3)
168 Touchpad Informatics Practices-XI

