Experiment 2
NAME – SAKSHAM YADAV
BATCH – 26
SAP ID - 590024978
Aim:
1. Check whether the given number is divisible by 3 and 5 both.
2. Check whether a given number is multiple of five or not.
3. Find the greatest among the two numbers. If numbers are equal than print
“numbers are equal”.
4. Find the greatest among three numbers assuming no two values are same.
5. Check whether the quadratic equation has real roots or imaginary roots.
Display the roots.
6. Find whether a given year is a leap year or not.
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
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: [Link]. CSE AI&ML
Subject name: Marks
PDS: 70
Python: 80
Chemistry: 90
English: 60
Physics: 50
Percentage: 70%
CGPA:7.0
Grade:
Theory:
1. Check whether a number is divisible by 3 and 5
Theory:
In Python, the modulus operator % is used to check divisibility.
If a number gives remainder 0 when divided by both 3 and 5, then it is divisible by both.
2. Check whether a number is a multiple of 5
Theory:
A number is a multiple of 5 if dividing it by 5 gives remainder 0.
The % operator is used to check this condition in Python.
3. Find the greatest among two numbers
Theory:
Python uses if–elif–else statements to compare numbers.
The program checks which number is greater, or prints “numbers are equal” if both
values are same.
4. Find the greatest among three numbers
Theory:
Three numbers are compared using conditional statements and logical operators.
The number greater than the other two is considered the greatest.
5. Check nature of roots of a quadratic equation
Theory:
For a quadratic equation ax² + bx + c = 0, the discriminant is
D = b² – 4ac.
D > 0 → real and distinct roots
D = 0 → real and equal roots
D < 0 → imaginary roots
Roots are calculated using the quadratic formula.
6. Check whether a year is a leap year
Theory:
In Python, a year is a leap year if:
It is divisible by 400, OR
It is divisible by 4 but not by 100
Conditional statements are used to apply these rules.
7. Display the next date
Theory:
The program takes day, month, and year as input and prints the next date.
It checks:
Number of days in the month
Leap year condition for February
Month and year change at the end of a month
8. Print grade sheet of a student
Theory:
Marks of five subjects are taken as input.
Percentage and CGPA are calculated as:
Percentage = (total / 500) * 100
CGPA = Percentage / 10
Grades are assigned using if–elif based on CGPA range.
PYTHON CODES :
1)
2)
3)
4)
5)
6)
7)
8)
Output:
1)
2)
3)
4)
5)
6)
7)
8)
LEARNING OUTCOMES :
This experiment focuses on the use of conditional statements in Python to
make decisions based on given conditions. Using if, elif, and else, different
programs were written to check divisibility, compare numbers, find leap
years, determine the nature of quadratic roots, calculate the next date, and
generate a student grade sheet. Logical and comparison operators were
used to evaluate multiple conditions. This experiment helped in
understanding how Python executes different blocks of code depending on
input values and conditions.