0% found this document useful (0 votes)
37 views9 pages

Practice Questions On Conditional Statements

The document contains examples of Python code for conditional statements. It includes programs to check voter eligibility based on age, identify traffic lights, grade students based on their marks, calculate student percentages and marks, determine if a number is positive or negative, check if a number is divisible by 5, and identify triangle types.

Uploaded by

satyamsingh99344
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views9 pages

Practice Questions On Conditional Statements

The document contains examples of Python code for conditional statements. It includes programs to check voter eligibility based on age, identify traffic lights, grade students based on their marks, calculate student percentages and marks, determine if a number is positive or negative, check if a number is divisible by 5, and identify triangle types.

Uploaded by

satyamsingh99344
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Practice Questions on conditional

statements
1) To check whether you are eligible to vote or not
Your program should get the age of the voter from the user
and if their age is 18 and above, let them vote otherwise
deny them from voting.

age = int(input("Enter age : "))


if age >= 18:
print("Eligible for Voting!")
else:
print("Not Eligible for Voting!")
2) Traffic light
Write a python program that will check for the
following conditions:
If the light is green – Car is allowed to go
If the light is yellow – Car has to wait
If the light is red – Car has to stop
Other signal – unrecognized signal. Example
black, blue, etc…
CODE:2
signal = input("What is a traffic signal? :").title()
if signal == "Red":
 print("Stop your car!")
elif signal == "Yellow":
 print("Wait your car!")
elif signal == "Green":
 print("You are allowed to go!")
else:
 print("Unrecgonized signal!")
3) Write a program to check students’ grades. Your
program should fulfill the following conditions:
Grade A – Outstanding
Grade B – Excellent
Grade C – Very Good
Grade D – Good
Grade E – Satisfactory
others – Unrecognized
CODE:3
 name = input("Enter student name:")
 clas = input("Enter class:")
 section = input("Enter section:")
 grade = input("Enter students grade:").upper()
 print("--------------------")
 print("Name:", name)
 print("Class:", clas)
 print("Section:", section)
 if grade == "A":
 print("Grade: Outstanding!")
 elif grade == "B":
 print("Grade: Excellent!")
 elif grade == "C":
 print("Grade: Very Good!")
 elif grade == "D":
 print("Grade: Good!")
 elif grade == "E":
 print("Grade: Satisfactory!")
 else:
 print("Unrecognized Grade!")
4) Students result with grade
 Modify the earlier program students’ grades in such a way that
they should take in five subject marks. Find the total mark and
their percentage. Your program should check for the following
conditions:
 If the percentage falls below 45, they are considered fail.
 If the percentage is between 45 and 60, grade them as pass.
 If the percentage is between 60 and 75, grade them as good.
 If the percentage is between 75 and 85, grade them as very good.
 If the percentage is between 85 and 100, grade them excellent.
 If the percentage is below zero or above 100, it’s an error.
Code:4
eng = int(input("Enter English mark:"))
dzo = int(input("Enter Dzongkha mark:"))
math = int(input("Enter Math mark:"))
his = int(input("Enter History mark:"))
geo = int(input("Enter Geography mark:"))

total_mark = eng + dzo + math + his + geo


percentage = total_mark / 5

print("\n---------Printing result-------------")
print("Name:", name)
print("Class:", clas)
print("Section:", section)
print("Percentage:", percentage,"%")
if percentage < 0 or percentage > 100:
print("Error: percentage should be between 0 and 100 only!")
elif percentage < 45:
print("Failed!")
elif percentage >= 45:
print("Error: percentage should be between 0 and 100 only!")
elif percentage < 45:
print("Failed!")
elif percentage >= 45:
print("Pass!")
if percentage >=45 and percentage < 60:
print("Remark: Just passed!")
elif percentage >= 60 and percentage < 75:
print("Remark: Good!")
elif percentage >= 75 and percentage < 85:
print("Remark: Very Good!")
elif percentage >= 85 and percentage < 100:
print("Remark: Excellent!")
5) Find the given number is positive or negative number.
6)Find the given number is divisible by 5 or not
7) If the triangle is an acute angle triangle, determine
further whether the triangle is equilateral, isosceles, or
scalene.
Code:7
print("Input lengths of the triangle sides: ")
 x = int(input("x: "))
 y = int(input("y: "))
 z = int(input("z: "))
if x == y == z:
print("Equilateral triangle")
elif x==y or y==z or z==x:
 print("isosceles triangle")
else:
 print("Scalene triangle")

You might also like