0% found this document useful (0 votes)
4 views3 pages

Chapter 4

Chapter 4 covers decision structures in programming, including logical expressions and code predictions. It provides examples of Python programs for finding roots of quadratic equations, determining if a number is odd or even, calculating employee bonuses, and displaying the day's name based on a given date. The chapter emphasizes the importance of conditional statements and logical operations in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Chapter 4

Chapter 4 covers decision structures in programming, including logical expressions and code predictions. It provides examples of Python programs for finding roots of quadratic equations, determining if a number is odd or even, calculating employee bonuses, and displaying the day's name based on a given date. The chapter emphasizes the importance of conditional statements and logical operations in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Chapter 4 – Decision Structures

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

Enter mark 110


Enter mark 25
Fail
3 Write a python program to find the roots of a quadratic equation.
import math
a = float(input("Enter coefficient a: "))
b = float(input("Enter coefficient b: "))
c = float(input("Enter coefficient c: "))
discriminant = b**2 - 4*a*c
if discriminant < 0:
print("The roots are imaginary.")
else:
root1 = (-b + math.sqrt(discriminant)) / (2*a)
root2 = (-b - math.sqrt(discriminant)) / (2*a)
print(f"The roots of the quadratic equation are: {root1} and {root2}")

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

name = input("Enter employee name: ")


grade = input("Enter employee grade (A/B/C): ")
basic_pay = float(input("Enter employee basic pay: "))

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

dearness_allowance = DEARNESS_ALLOWANCE_PERCENTAGE / 100 *


basic_pay
hra = HRA_PERCENTAGE / 100 * basic_pay
cca = CCA_PERCENTAGE / 100 * basic_pay
bonus = allowance_percentage / 100 * basic_pay

total_salary = basic_pay + dearness_allowance + hra + cca +


CONVEYANCE_ALLOWANCE + bonus
print(f"\nEmployee Details\nName: {name}\nGrade: {grade}\nBasic Pay:
{basic_pay}\nDearness Allowance: {dearness_allowance}\nHRA: {hra}\nCCA:
{cca}\nConveyance Allowance: {CONVEYANCE_ALLOWANCE}\nBonus:
{bonus}\nTotal Salary: {total_salary}")
6 Write a program to display the day’s name, given the date of a specific month.
import datetime

date = int(input("Enter the date (1-31): "))


month = int(input("Enter the month (1-12): "))

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}")

COPYRIGHT © 2023 PEARSON INDIA EDUCATION SERVICES PVT. LTD

You might also like