0% found this document useful (0 votes)
758 views

PWP Practical No. 4

The document contains 6 Python programs that demonstrate the use of conditional statements like if, if-else, and nested if statements. The programs check if a number is even or odd, find the absolute value of numbers, determine the largest of three numbers, check if a year is a leap year, identify if a number is positive, negative or zero, and calculate the grade based on the average of 5 subjects' marks.

Uploaded by

Rutuja Bhagat
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)
758 views

PWP Practical No. 4

The document contains 6 Python programs that demonstrate the use of conditional statements like if, if-else, and nested if statements. The programs check if a number is even or odd, find the absolute value of numbers, determine the largest of three numbers, check if a year is a leap year, identify if a number is positive, negative or zero, and calculate the grade based on the average of 5 subjects' marks.

Uploaded by

Rutuja Bhagat
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/ 2

Practical No.

4: Write simple Python program to demonstrate use of


Conditional statements: if’ statement, ‘if … else’ statement, Nested ‘if’
statement.

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


num = int(input("Enter a number: "))
if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))

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


int_num = -25
float_num = -10.50
print("The absolute value of an integer number is:", abs(int_num))
print("The absolute value of a float number is:", abs(float_num))
complex_number = 3-4j
abs_number = abs(complex_number)
print("The absolute value of a float number is:",abs_number)

3. Write a program to check the largest number among the three numbers
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))

if (num1 >= num2) and (num1 >= num3):


largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3

print("The largest number is: ", largest)

4. Write a program to check if the input year is a leap year of not


year = int(input("Enter a year: "))
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))

5. Write a program to check if a Number is Positive, Negative or Zero


num = float(input("Enter a number: "))
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")

6. Write a program that takes the marks of 5 subjects and displays the grade.
sub1=int(input("Enter marks of the first subject:\n "))
sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: \n"))
avg=(sub1+sub2+sub3+sub4+sub4)/5
if(avg>=90):
print("Grade: A")
elif(avg>=80&avg<90):
print("Grade: B")
elif(avg>=70&avg<80):
print("Grade: C")
elif(avg>=60&avg<70):
print("Grade: D")
else:
print("Grade: F")

You might also like