0% found this document useful (0 votes)
5 views4 pages

Practical N0:-4 Name:-Shweta Chavan Patil Roll No:-3207 1.if

The document contains practical exercises demonstrating the use of conditional statements in Python, including if, if-else, and nested if structures. It provides examples for checking eligibility for a driving license, comparing numbers, determining positivity or negativity, checking for even or odd numbers, calculating absolute values, finding the largest number among three inputs, verifying leap years, and calculating grades based on average marks. Each exercise includes input prompts and expected outputs.
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)
5 views4 pages

Practical N0:-4 Name:-Shweta Chavan Patil Roll No:-3207 1.if

The document contains practical exercises demonstrating the use of conditional statements in Python, including if, if-else, and nested if structures. It provides examples for checking eligibility for a driving license, comparing numbers, determining positivity or negativity, checking for even or odd numbers, calculating absolute values, finding the largest number among three inputs, verifying leap years, and calculating grades based on average marks. Each exercise includes input prompts and expected outputs.
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/ 4

Practical N0:-4

Name:-Shweta Chavan Patil Roll No:-3207

1.If

a=int(input("Enter value of a="))

if a>=18:

print("You are eligible for driving licence")

Output:-

2.If else

a=int(input("Enter value of a="))

b=int(input("Enter value of b="))

if a>b:

print("a is greater than b")

else:

print("b is greater than a")

3.Nested If

a=int(input("Enter value"))

if a>0:
print("a is positive")

elif a<0:

print("a is negative")

else:

print("a is 0")

Output:-

Exercise:-

1.

num = int(input("Enter a number: "))


if num % 2 == 0:
print("Even")
else:
print("Odd")

Output:-
2.
num = float(input("Enter a number: "))
abs_value = abs(num)
print("The absolute value is:", abs_value)

Output:-

3.

num1 = float(input("Enter the first number: "))


num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
largest = max(num1, num2, num3)
print("The largest number is:", largest)

Output:-

4.
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(f"{year} is a leap year.")
else:
print(f"{year} is not a leap year.")
Output:
5.

subject1 = float(input("Enter marks for subject 1: "))


subject2 = float(input("Enter marks for subject 2: "))
subject3 = float(input("Enter marks for subject 3: "))
subject4 = float(input("Enter marks for subject 4: "))
subject5 = float(input("Enter marks for subject 5: "))
total_marks = subject1 + subject2 + subject3 + subject4 + subject5
average_marks = total_marks / 5
if average_marks >= 90:
grade = "A+"
elif average_marks >= 80:
grade = "A"
elif average_marks >= 70:
grade = "B"
elif average_marks >= 60:
grade = "C"
elif average_marks >= 50:
grade = "D"
else:
grade = "F"
print(f"Total Marks: {total_marks}")
print(f"Average Marks: {average_marks:.2f}")
print(f"Grade: {grade}")

Output:-

You might also like