0% found this document useful (0 votes)
9 views8 pages

Conditional Statements

The document contains a series of programming exercises focused on conditional statements in Python. It includes code examples for checking divisibility, finding the greatest number, determining leap years, calculating quadratic roots, and generating a student's grade sheet based on marks. Each exercise is accompanied by input prompts and expected outputs.

Uploaded by

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

Conditional Statements

The document contains a series of programming exercises focused on conditional statements in Python. It includes code examples for checking divisibility, finding the greatest number, determining leap years, calculating quadratic roots, and generating a student's grade sheet based on marks. Each exercise is accompanied by input prompts and expected outputs.

Uploaded by

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

Name: Gurkirat Singh

Sap ID: 590012199

Experiment 3 : Conditional Statements

1. Check whether given number is divisible by 3 and 5 both.


Code
x=int(input("Entere a number: "))
if x % 3 == 0 and x % 5 == 0:
print(f"{x} is divisible by 3 and 5.")
else:
print(f"{x} is not divisible by 3 and 5.")
Output…

2. Check whether a given number is multiple of five or not.


Code
x=int(input("Enter a number: "))
if x%5==0:
print(f"Yes,{x} is a multiple of 5.")
else:
print(f"No,{x} is not a multiple of 5.")
output…
3. Find the greatest among two numbers. If numbers are equal than
print “numbers are equal”.
Code
x1=int(input("Enter first number: "))
x2=int(input("Enter second number: "))
if x1 > x2:
print(f"{x1} is greater than {x2}")
elif x1 < x2:
print(f"{x2} is greater than {x1}")
elif x1 == x2:
print("Both are equal")
Output…

4. Find the greatest among three numbers assuming no two values


are same.
Code
x1=int(input("Enter first number: "))
x2=int(input("Enter second number: "))
x3=int(input("Enter third number: "))
if x1 > x2 and x1 > x3:
print(f"The greatest number is: {x1}")
elif x2 > x1 and x2 > x3:
print(f"The greatest number is: {x2}")
else:
print(f"The greatest number is: {x3}")
Output…

5. Check whether the quadratic equation has real roots or imaginary


roots. Display the roots.
Code
a=float(input("enter the coefficient a :"))
b=float(input("enter the coefficient b :"))
c=float(input("enter the coefficient c :"))
print("coefficient are :", "b" ,"=", b, "a","=",a, "c","=",c)
D=b**2-(4*a*c)
print(D)
if(D>0):
print("the roots are real and roots are :",-b-(D*0.5)/2*a,-b+(D*0.5)/2*a)
elif(D<0):
print("the roots are imaginary and roots are:",-b-(D*0.5)/2*a,-
b+(D*0.5)/2*a)
else:
print("double root",-b/2*a)
output…
6. Find whether a given year is a leap year or not
Code
y = int(input("Enter a year: "))
if (y % 4 == 0 and y % 100 != 0) or (y % 400 == 0):
print(f"{y} is a leap year.")
else:
print(f"{y} is not a leap year.")
output…

7. Write a program which takes any date as input and display next
date of the calendar e.g. I/P: day=20 month=9 year=2005 O/P:
day=21 month=9 year 2005
Code
d = int(input("Enter day: "))
m = int(input("Enter month: "))
y = int(input("Enter year: "))
if (y % 4 == 0 and y % 100 != 0) or (y % 400 == 0):
leap_year = True
else:
leap_year = False
if m in [1, 3, 5, 7, 8, 10, 12]:
days_in_month = 31
elif m in [4, 6, 9, 11]:
days_in_month = 30
elif m == 2:
days_in_month = 29 if leap_year else 28
if d < days_in_month:
d += 1
else:
d=1
if m < 12:
m += 1
else:
m=1
y += 1
print(f"Next Date: {d}/{m}/{y}")
output…

8. Print the grade sheet of a student for the given range of cgpa.
Scan marks of five subjects and calculate the percentage.
CGPA=percentage/10 CGPA range: 0 to 3.4 -> F 3.5 to 5.0->C+
5.1 to 6->B 6.1 to 7-> B+ 7.1 to 8-> A 8.1 to 9->A+ 9.1 to 10-> O
(Outstanding) Sample Gradesheet Name: Rohit Sharma Roll
Number: R17234512 SAPID: 50005673 Sem: 1 Course: B.Tech.
CSE AI&ML Subject name: Marks PDS: 70 Python: 80 Chemistry:
90 English: 60 Physics: 50 Percentage: 70% CGPA:7.0 Grade:
Code
name = input("Enter the student's name: ")
roll_number = input("Enter the roll number: ")
sapid = input("Enter the SAPID: ")
semester = input("Enter the semester: ")
course = input("Enter the course: ")

subject1 = int(input("Enter marks for MAths: "))


subject2 = int(input("Enter marks for Linux: "))
subject3 = int(input("Enter marks for Programming in C: "))
subject4 = int(input("Enter marks for Problem Solving: "))
subject5 = int(input("Enter marks for Environment: "))

total_marks = subject1 + subject2 + subject3 + subject4 + subject5


percentage = total_marks / 5

cgpa = percentage / 10

if cgpa <= 3.4:


grade = "F"
elif cgpa <= 5.0:
grade = "C+"
elif cgpa <= 6.0:
grade = "B"
elif cgpa <= 7.0:
grade = "B+"
elif cgpa <= 8.0:
grade = "A"
elif cgpa <= 9.0:
grade = "A+"
elif cgpa <= 10.0:
grade = "O (Outstanding)"
else:
grade = "Invalid CGPA"

print("\nSample Gradesheet")
print(f"Name: {name}")
print(f"Roll Number: {roll_number} SAPID: {sapid}")
print(f"Sem: {semester} Course: {course}")
print("Subject Marks:")
print(f"Subject 1: {subject1}")
print(f"Subject 2: {subject2}")
print(f"Subject 3: {subject3}")
print(f"Subject 4: {subject4}")
print(f"Subject 5: {subject5}")
print(f"Percentage: {percentage:.2f}%")
print(f"CGPA: {cgpa:.2f}")
print(f"Grade: {grade}")
output….
\

You might also like