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

Essential Python IF ELSE Programs

The document contains a series of Python programs demonstrating the use of if-else statements for various tasks, including checking if a number is even or odd, determining if a number is positive, negative, or zero, and finding the largest of two or three numbers. It also includes programs for checking leap years, voting eligibility, grading based on marks, performing basic arithmetic operations, and generating a mini bill. Each program prompts the user for input and provides output based on the conditions specified.
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)
6 views4 pages

Essential Python IF ELSE Programs

The document contains a series of Python programs demonstrating the use of if-else statements for various tasks, including checking if a number is even or odd, determining if a number is positive, negative, or zero, and finding the largest of two or three numbers. It also includes programs for checking leap years, voting eligibility, grading based on marks, performing basic arithmetic operations, and generating a mini bill. Each program prompts the user for input and provides output based on the conditions specified.
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

IF ELSE PROGRAMS:

1.​ Check if a Number is Even or Odd


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

if num % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")

2. Check if a Number is Positive, Negative, or Zero


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

if num > 0:
print("Positive number")
elif num < 0:
print("Negative number")
else:
print("Zero")

3. Find the Largest of Two Numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

if a > b:
print("The first number is greater.")
elif b > a:
print("The second number is greater.")
else:
print("Both numbers are equal.")

4. Check if a Year is a Leap Year


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

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):


print("Leap year")
else:
print("Not a leap year")
5. Check Eligibility to Vote
age = int(input("Enter your age: "))

if age >= 18:


print("You are eligible to vote.")
else:
print("You are not eligible to vote.")

6. Grade Based on Marks


marks = int(input("Enter your marks (out of 100): "))

if marks >= 90:


print("Grade: A")
elif marks >= 75:
print("Grade: B")
elif marks >= 60:
print("Grade: C")
elif marks >= 40:
print("Grade: D")
else:
print("Grade: F (Fail)")

7. Find the largest of three numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))

if a > b and a > c:


print("First number is the largest.")
elif b > c:
print("Second number is the largest.")
else:
print("Third number is the largest.")

8. Calculator Program - ADD

print("SIMPLE ADDITION CALCULATOR")


choice = int(input("Enter 1 to perform Addition: "))
if choice == 1:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("RESULT:\nYou selected ADDITION.\nThe sum is:", num1 +
num2)
else:
print("Invalid Choice!\nYou must enter 1 to add numbers.")

9. Simple Calculator Program

print("Simple Calculator")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")

choice = int(input("Enter your choice (1-4): "))

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


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

if choice == 1:
print("Result =", num1 + num2)

elif choice == 2:
print("Result =", num1 - num2)

elif choice == 3:
print("Result =", num1 * num2)

elif choice == 4:
if num2 != 0:
print("Result =", num1 / num2)
else:
print("Cannot divide by zero!")
else:
print("Invalid choice!")

10. Mini bill generator

item = input("Enter item name: ")


price = float(input("Enter price of the item: "))
quantity = int(input("Enter quantity: "))
amount = price * quantity

print("\n----- Bill Summary -----")


print("Item:", item)
print("Price:", price)
print("Quantity:", quantity)
print("Total Amount to be Paid =", amount)

You might also like