Chapter 4
Chapter 4
Programming Questions
1 Write logical expressions for the following:
A. Either A is greater than B or A is less than C
(A>B) or (A<C)
B. The favourite city is either Mumbai or Chennai
(favourite_city == "Mumbai") or (favourite_city == "Chennai")
C. Either the place is Bengaluru or Chennai and not Hyderabad
(place == "Bengaluru" or place == "Chennai") and place != "Hyderabad"
D. Mark is either greater than 60 but not less than 90
(Mark > 60) and (Mark <= 90)
2 Predict the output of the code
A. x = 4
if x > 5:
print(‘True’)
else
print(‘False’)
False
B.
x,y = 4, 6
if (x+y) >= 10
print(‘True’)
else:
print(‘False’)
True
C.
year = 2000
if (year % 100) = 100:
print (‘Probably leap year’)
else
print (Not a leap year’)
Error (Because of “=” in Condition)
D.
x=1
if (x ==1):
x=x+3
else
x = x + 10
print(‘x=’,x)
x=4
E.
m1 = int(input(“Enter mark 1”))
m2 = int(input(“Enter mark 2”)
if (m1+m2) > 50:
print(‘Pass’)
else:
print(‘Fail’)
Enter mark 110
COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD
Enter mark 240
Fail
4 Write a program to find whether the given number is odd or even and positive or
negative.
num = int(input("Enter a number: "))
if num % 2 == 0:
print(f"{num} is even.")
else:
print(f"{num} is odd.")
if num > 0:
print(f"{num} is positive.")
elif num < 0:
print(f"{num} is negative.")
else:
print("The number is zero.")
5 Write a program to calculate bonuses for employees based on grade and basic pay.
(Given name, grade, basic pay, dearness allowance, HRA, CCA, conveyance, etc.)
GRADE_A_ALLOWANCE_PERCENTAGE = 20
GRADE_B_ALLOWANCE_PERCENTAGE = 15
GRADE_C_ALLOWANCE_PERCENTAGE = 10
DEARNESS_ALLOWANCE_PERCENTAGE = 10
HRA_PERCENTAGE = 8
CCA_PERCENTAGE = 3
CONVEYANCE_ALLOWANCE = 5000
if grade == "A":
COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD
allowance_percentage = GRADE_A_ALLOWANCE_PERCENTAGE
elif grade == "B":
allowance_percentage = GRADE_B_ALLOWANCE_PERCENTAGE
else:
allowance_percentage = GRADE_C_ALLOWANCE_PERCENTAGE
year = datetime.date.today().year
date_obj = datetime.date(year, month, date)
day_name = date_obj.strftime("%A")
print(f"The day on {month}/{date}/{year} was {day_name}")