Practical No. 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Practical No. 3: Programs based on Decision making.

Practical Significance :
Practical Significance Decision making is anticipation of conditions occurring while execution of the program
and specifying actions taken according to the conditions. Decision structures evaluate multiple expressions
which produce TRUE or FALSE as outcome. Students need to determine which action to take and which statements
to execute if outcome is TRUE or FALSE otherwise

CO2: Interpret the python syntax and semantics of control flow statements
LO2: Develop logical thinking to solve the problems using programming fundamental concepts.

Title of Practical:
1. Write a program to read marks from keyboard and your program should display equivalent grade
according to following table(else-if ladder)
Marks Grade
100 - 80 Distinction
79 - 60 First Class
59 - 40 Second Class
< 40 Fail

Program Code:
marks=int(input("enter marks of studnet"))
if(marks>=80):
print("Grade: Distinction")
elif(marks>=60) and (marks<=79):
print("Grade: First Class")
elif(marks>=40) and (marks<=59):
print("Grade: Second Class")
else:
print("Grade: Fail")

o/p of program
enter marks of studnet65
Grade: First Class
2. Write a program to input basic salary of an employee and calculate gross salary according to given
conditions.
Basic Salary <= 10000 : HRA = 20%, DA = 80%
Basic Salary is between 10001 to 20000 : HRA = 25%, DA = 90%
Basic Salary >= 20001 : HRA = 30%, DA = 95%
Program Code
b_s=int(input("enter basic salary of an employee"))
if(b_s <=10000):
hra=20*b_s/100
da=80*b_s/100
elif (b_s>=10001) and (b_s<=20000):
hra=25*b_s/100
da=90*b_s/100
else:
hra=30*b_s/100
da=95*b_s/100
g_s=b_s+hra+da
print("basic salary of an employee:",b_s)
print("HRA of an employee:",hra)
print("DA of an employee:",da)
print("Gross salary of an employee:",g_s)

o/p of program
enter basic salary of an employee 2000

basic salary of an employee: 2000

HRA of an employee: 400.0

DA of an employee: 1600.0

Gross salary of an employee: 4000.0

3. If the ages of three brothers are input through the keyboard, write a C Program to determine the
youngest and oldest of the three.

Program Code:

bro1 = int(input("Enter age of first member: "))

bro2 = int(input("Enter age of second member : "))

bro3 = int(input("Enter age of third member: "))

if (bro1 >= bro2) and (bro1 >= bro3):

oldest = bro1

elif (bro2 >= bro1) and (bro2 >= bro3):


oldest = bro2

else:

oldest = bro3

print("The oldest brother age is", oldest)

if (bro1 <= bro2) and (bro1 <= bro3):

yongest = bro1

elif (bro2 <= bro1) and (bro2 <= bro3):

yongest = bro2

else:

yongest = bro3

print("The yongest brother age is", yongest)

o/p of program
Enter age of first member: 25

Enter age of second member : 45

Enter age of third member: 12

The oldest brother age is 45

The yongest brother age is 12

4. Write a program for checking the speed of drivers.

If speed is less than 70, it should print “Ok”. Otherwise, for every 5km above the speed limit (70), it
should give the driver one demerit point and print the total number of demerit points. For example, if
the speed is 80, it should print: “Points: 2”. If the driver gets more than 12 points, the function should
print: “License suspended”
Program Code:

speed=int(input("enter speed "))


if speed <= 70:
print ("OK")
else:
speed1 = (speed-70)//5
if speed1 <= 12:
print(f"Point: {speed1}")
else:
print("License suspended")
o/p of program

enter speed 80
Point: 2
enter speed 135
License suspended

You might also like