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

Conditional Statements Programs

The document contains multiple code snippets demonstrating various programming tasks such as grading systems, college admission eligibility, bill calculations, clothing advice based on weather, ATM withdrawal validation, student result declaration, electricity bill calculations, age group classification, train ticket fare calculations, and a simple menu-based calculator. Each section includes a code example, its logic, and the expected output. The code snippets illustrate the use of conditional statements and calculations in Python.
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)
20 views5 pages

Conditional Statements Programs

The document contains multiple code snippets demonstrating various programming tasks such as grading systems, college admission eligibility, bill calculations, clothing advice based on weather, ATM withdrawal validation, student result declaration, electricity bill calculations, age group classification, train ticket fare calculations, and a simple menu-based calculator. Each section includes a code example, its logic, and the expected output. The code snippets illustrate the use of conditional statements and calculations in Python.
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

1.

Grading System with Subject-Wise Conditions

Code:
# Program to calculate grade based on subject marks
math = 85
science = 78
english = 90
history = 88
geography = 92

average = (math + science + english + history + geography) / 5

if average >= 90:


grade = "A+"
elif average >= 80:
grade = "A"
elif average >= 70:
grade = "B"
elif average >= 60:
grade = "C"
else:
grade = "D"

print("Average Marks:", average)


print("Grade:", grade)
Output:
Average Marks: 86.6
Grade: A

2. Eligibility for College Admission

Code:
# Program to check eligibility for college admission
math = 75
physics = 65
chemistry = 70

if math >= 60 and physics >= 50 and chemistry >= 55:


if (math + physics + chemistry) >= 200:
print("Eligible for admission")
elif (math + physics) >= 140:
print("Eligible under special criteria")
else:
print("Not eligible")
else:
print("Not eligible due to subject marks")
Output:
Eligible for admission

3. Bill Calculation with Discounts and Conditions

Code:
# Program to calculate final bill with discounts
bill_amount = 1500
customer_type = "Premium"

if customer_type == "Regular":
if bill_amount > 1000:
discount = 0.1
else:
discount = 0.05
elif customer_type == "Premium":
if bill_amount > 1000:
discount = 0.2
else:
discount = 0.1
else:
discount = 0

final_amount = bill_amount - (bill_amount * discount)


print("Discount Applied:", discount * 100, "%")
print("Final Bill Amount:", final_amount)
Output:
Discount Applied: 20.0 %
Final Bill Amount: 1200.0

4. Weather Clothing Advice System

Code:
# Suggest clothing based on weather
temperature = 15
raining = True
wind_speed = 25

if temperature < 10:


print("Wear a heavy jacket.")
elif temperature < 20:
if raining:
print("Wear a waterproof jacket.")
elif wind_speed > 20:
print("Wear a windbreaker.")
else:
print("Wear a light sweater.")
else:
if raining:
print("Take an umbrella.")
else:
print("T-shirt is fine.")

print("Temperature:", temperature)
print("Raining:", raining)
print("Wind Speed:", wind_speed)
Output:
Wear a waterproof jacket.
Temperature: 15
Raining: True
Wind Speed: 25
5. ATM Withdrawal Validation

Code:
# ATM withdrawal program with multiple conditions
balance = 5000
withdraw_amount = 1200

if withdraw_amount > balance:


print("Insufficient funds.")
elif withdraw_amount % 100 != 0:
print("Enter amount in multiples of 100.")
elif withdraw_amount > 2000:
print("Withdrawal limit exceeded.")
else:
balance -= withdraw_amount
print("Withdrawal Successful!")
print("Remaining Balance:", balance)
Output:
Withdrawal Successful!
Remaining Balance: 3800

6. Student Result Declaration System

Code:
# Program to declare pass/fail with distinction
marks = [65, 70, 80, 55, 60]

fail_count = 0
for mark in marks:
if mark < 40:
fail_count += 1

if fail_count > 0:
print("Result: Fail")
elif all(mark >= 75 for mark in marks):
print("Result: Distinction")
elif sum(marks)/len(marks) >= 60:
print("Result: Pass")
else:
print("Result: Needs Improvement")
Output:
Result: Pass

7. Electricity Bill with Slab-wise Charges

Code:
# Program to calculate electricity bill
units = 350

if units <= 100:


amount = units * 1.5
elif units <= 300:
amount = 100 * 1.5 + (units - 100) * 2.5
else:
amount = 100 * 1.5 + 200 * 2.5 + (units - 300) * 4

print("Total Units:", units)


print("Bill Amount: Rs.", amount)
Output:
Total Units: 350
Bill Amount: Rs. 875.0

8. Age Group Classification

Code:
# Classify person based on age
age = 45

if age < 0:
print("Invalid age.")
elif age <= 12:
print("Child")
elif age <= 19:
print("Teenager")
elif age <= 59:
print("Adult")
else:
print("Senior Citizen")
Output:
Adult

9. Train Ticket Fare Calculation

Code:
# Train fare based on distance and class
distance = 220
travel_class = "AC"

if travel_class == "Sleeper":
fare = distance * 1.5
elif travel_class == "AC":
fare = distance * 2.5
elif travel_class == "General":
fare = distance * 1.0
else:
fare = 0

if fare > 0:
print("Fare for", travel_class, "class:", fare)
else:
print("Invalid travel class")
Output:
Fare for AC class: 550.0

10. Simple Menu-Based Calculator

Code:
# Simple calculator with choices
a = 20
b = 4
operation = "divide"

if operation == "add":
print("Sum:", a + b)
elif operation == "subtract":
print("Difference:", a - b)
elif operation == "multiply":
print("Product:", a * b)
elif operation == "divide":
if b != 0:
print("Quotient:", a / b)
else:
print("Cannot divide by zero.")
else:
print("Invalid operation.")
Output:
Quotient: 5.0

You might also like