We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
In [4]:
In [2]:
Day -4
Control Flow Statements in Python
if Condition
* write a program to calulate the percentage of the student in the subjects Maths, Science,
social, english and hindi. ask the user to give the input"
input("Enter the name of a student"
input("enter the marks scored in englis!
= input ("enter the marks scored in hindi")
input("enter the marks scored in maths")
input("enter the marks scored in scienc
= input (“enter the marks scored in social")
int(a)+int (b)+int (c)+int(d)+int(e)
(p/500)*100
print("percent scored by the student", x, "is", ny
Enter the name of a studentayush
enter the marks scored in english78
enter the marks scored in hindi69
enter the marks scored in maths89
enter the marks scored in sciencea2
enter the marks scored in social9®
percent scored by the student ayush is 81.6 %
= 10
if (i > 15):
print("1@ is less than 15")
print("I am outside the if condition")
I am outside the if condition
For example, assigning grades (A, B, C) based on marks obtained by a student
if the percentage is above 9@, assign grade
if the percentage is above 75, assign grade B
if the percentage is above 65, assign grade CIn [4]:
In [5]:
In [6]
In [8]
a =int(input("enter the marks scored by a student"))
Af arse:
print("student has obtained A grade")
if a>=75 and a<90:
print("student has obtained 8 grade")
if a>=65 and a<75:
print("student has obtained C grade")
enter the marks scored by a students5
student has obtained 8 grade
if else statement
Write a program to display "Hello" if the number entered by a user is a multiple of 5 other wise
print "bye"
a = int(input("Enter the number"))
if ax
print("Hello")
else:
print("Bye")
Enter the nunber2s
Hello
Write a program to check whether a persn is eligible for voting or not,
age = int(input("enter the age of a citizen"))
if age>=18:
print("You are eligible for voting")
else:
print("you are not eligible for voting”)
enter the age of a citizen25
You are eligible for voting
write a program to check whether the number entered by a user is positive or negative
a = int(input("Enter the numbe
if a>o:
print("The number you have entered is a positive number")
else:
print("The number you have entered is a negative number ")
"))
Enter the nunber-9
The number you have entered is a negative numberIn [ ]:
In [13]:
In({]
In [18]
if-elif- else statement
Accept any city from the user and display the monument of the city
delhi - Red Fort
Agra - Taj mahal
Jaipur - Jalmahal
Orissa - Konark Temple
Hyderabad - Charminar
a = input(“enter the city")
if a == "Delhi":
print("The monument of Delhi is Red Fort")
elif a == "Agra"
print("The monument of Agra is Tajmahal")
elif a == "Jaipur":
print("The monument of Jaipur is Jalmahal")
elif a == "Orissa":
print("The monument of Orissa is Konark Temple’
elif a == "Hyderabad":
print("The monument of Hyderabad is Charminar
else:
print("No record found")
enter the citylucknow
No record found
Accept the number of days from the user and calculate the charge of a library <
the following
till 5 days - 2Rs per day
six to ten days - 3Rs per day
11 to 15 days - 4Rs per day
after 15 days - SRs per day
m = int(input("enter the number of days you want to keep the book"
if m=:
print("you need to pay", m*2, "R:
elif m>=6 and mc=10:
print("you need to pay", m*3, "Rs")
elif m>=11 and me=15
print("you need to pay", m*4, "Rs")
elif mis:
print("you need to pay", m*5,"Rs")
)
enter the nunber of days you want to keep the book25
you need to pay 125 RsInt]: