Python assignment
Conditional statement
Code
#1
marks =int(input("Enter the marks of the student: "))
if marks >= 40:
print("Pass")
else:
print("Fail")
print("\n")
#2
salary = int(input("Enter the salary of the employee: "))
if salary > 60000:
print("Grade I")
else:
print("Grade II")
print("\n")
#3
number = int(input("Enter a number: "))
if number % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")
print('\n')
#4
principal = int(input("Enter the principal amount: "))
time = int(input("Enter the time (in years): "))
if principal < 60000:
rate = 9
else:
rate = 11
simple_interest = (principal * rate * time) / 100
total_amount = principal + simple_interest
print(f"Rate of Interest: {rate}%")
print(f"Simple Interest: {simple_interest}")
print(f"Total Amount: {total_amount}")
print('\n')
#5
income = int(input("Enter the income of the employee: "))
tax = 0
surcharge = 0
if income < 15000:
tax_percentage = 15
surcharge_percentage = 7
elif 15001 <= income <= 25000:
tax_percentage = 18
surcharge_percentage = 11
else:
tax_percentage = 20
surcharge_percentage = 13
tax = (income * tax_percentage) / 100
surcharge = (income * surcharge_percentage) / 100
total_income = income - (tax + surcharge)
print(f"Income: Rs. {income}")
print(f"Tax: Rs. {tax}")
print(f"Surcharge: Rs. {surcharge}")
print(f"Total Income after Tax and Surcharge: Rs. {total_income}")
print('\n')
#6
average_marks = int(input("Enter the average marks of the student: "))
if average_marks < 40:
division = "Failed"
elif 40 <= average_marks < 50:
division = "Third"
elif 50 <= average_marks < 60:
division = "Second"
else:
division = "First"
print(f"Division: {division}")
#7
print('\n')
distance = float(input("Enter the distance to be traveled (in km): "))
fare = 0
if distance <= 20:
fare = distance * 10
elif distance <= 40:
fare = (20 * 10) + ((distance - 20) * 7)
else:
fare = (20 * 10) + (20 * 7) + ((distance - 40) * 6)
print(f"Fare for the distance of {distance} km is Rs. {fare}")
#8
print('\n')
days_attended = int(input("Enter the number of days attended: "))
charges = 0
if days_attended <= 5:
charges = days_attended * 80
elif days_attended <= 10:
charges = (5 * 80) + ((days_attended - 5) * 45)
else:
charges = (5 * 80) + (5 * 45) + ((days_attended - 10) * 20)
print(f"Charges for {days_attended} days attended are Rs. {charges}")
#9
print('\n')
units_consumed = float(input("Enter the number of units consumed: "))
bill = 0
if units_consumed <= 100:
bill = 0
elif units_consumed <= 300:
bill = (units_consumed - 100) * 2
elif units_consumed <= 650:
bill = (200 * 2) + (units_consumed - 300) * 4
else:
bill = (200 * 2) + (350 * 4) + (units_consumed - 650) * 6
print(f"The total electricity bill is: Rs {bill:.2f}")
#10
print('\n')
print("Temperature Conversion")
print("1. Celsius to Fahrenheit")
print("2. Fahrenheit to Celsius")
choice = input("Enter your choice (1 or 2): ")
if choice == '1':
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (9/5) * celsius + 32
print(f"{celsius} Celsius is equal to {fahrenheit:.2f} Fahrenheit")
elif choice == '2':
fahrenheit = float(input("Enter temperature in Fahrenheit: "))
celsius = (fahrenheit - 32) * 5/9
print(f"{fahrenheit} Fahrenheit is equal to {celsius:.2f} Celsius")
else:
print("Invalid choice! Please enter 1 or 2.")
Output