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

PWP 4

The document contains programs to check if a number is even or odd, find the absolute value of a number, find the largest of three numbers, check if a year is a leap year, check if a number is positive, negative, or zero, and calculate the grade from marks of five subjects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views4 pages

PWP 4

The document contains programs to check if a number is even or odd, find the absolute value of a number, find the largest of three numbers, check if a year is a leap year, check if a number is positive, negative, or zero, and calculate the grade from marks of five subjects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PRACTICAL NO.

 XI] EXERCISE:

1) Write a program to check whether a number is even or odd

 Program Code:

# Get user input for the number

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

# Check if the number is even or odd

if number % 2 == 0:

print(f"{number} is an even number.")

else:

print(f"{number} is an odd number.")

OUTPUT

2) Write a program to find out absolute value of an input number

Program Code:

# Get user input for the number

number = float(input("Enter a number: "))

# Calculate the absolute value

absolute_value = abs(number)

# Display the result

print(f"The absolute value of {number} is: {absolute_value}")

OUTPUT
3) Write a program to check the largest number among the three numbers

 Program Code:

# Get user input for three numbers

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

num2 = float(input("Enter the second number: "))

num3 = float(input("Enter the third number: "))

# Compare the numbers to find the largest one

if num1 >= num2 and num1 >= num3:

largest = num1

elif num2 >= num1 and num2 >= num3:

largest = num2

else:

largest = num3

# Display the result

print(f"The largest number among {num1}, {num2}, and {num3} is: {largest}")

OUTPUT

4) Write a program to check if the input year is a leap year or not

 Program Code:

# Get user input for the year

year = int(input("Enter a year: "))

# Check if the year is a leap 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) Write a program to check if a number is positive, negative, or zero

Program Code:

# Get user input for the number

number = float(input("Enter a number: "))

# Check if the number is positive, negative, or zero

if number > 0:

print(f"{number} is a positive number.")

elif number < 0:

print(f"{number} is a negative number.")

else:

print(f"{number} is zero.")

OUTPUT
6) Write a program that takes the marks of 5 subjects and displays the grade

Program Code:

# Get user input for marks in 5 subjects

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: "))

# Calculate the average marks

average_marks = (subject1 + subject2 + subject3 + subject4 + subject5) / 5

# Determine the grade based on the average marks

if 90 <= average_marks <= 100:

grade = 'A+'

elif 80 <= average_marks < 90:

grade = 'A'

elif 70 <= average_marks < 80:

grade = 'B'

elif 60 <= average_marks < 70:

grade = 'C'

elif 50 <= average_marks < 60:

grade = 'D'

else:

grade = 'F'

# Display the results

print(f"Average marks: {average_marks:.2f}")

print(f"Grade: {grade}")

OUTPUT

You might also like