Practice session WEEK #8
1. Create a program to manage airline ticket bookings based on the passenger's
selected class: "economy", "business", or "first".
a. Prompt the user to input details such as name, age, destination, and class
preference (economy, business, or first).
b. Validate inputs (e.g., ensure the name contains only letters, age is a positive
integer, and class selection is valid).
c. Display appropriate error messages for invalid entries and allow the user
to re- enter the data.
print("---- Airline Ticket Booking ----")
name = input("Enter passenger name: ")
age = input("Enter age: ")
destination = input("Enter destination: ")
travel_class = input("Enter class (economy/business/first): ").lower()
# Input validation
if [Link]():
if [Link]() and int(age) > 0:
if travel_class == "economy" or travel_class == "business" or travel_class == "first":
print("\n--- Booking Details ---")
print("Name:", name)
print("Age:", age)
print("Destination:", destination)
print("Class:", travel_class)
print("Ticket booked successfully!")
else:
print("Error: Invalid class selection.")
else:
print("Error: Age must be a positive integer.")
else:
print("Error: Name should contain only letters.")
output:
---- Airline Ticket Booking ----
Enter passenger name: girish
Enter age: 23
Enter destination: delhi
Enter class (economy/business/first): business
Dept. of CSE, SPT-Tumakuru 1
--- Booking Details ---
Name: girish
Age: 23
Destination: delhi
Class: business
Ticket booked successfully!
2. Build a system to suggest clothing based on the temperature.
a. If temperature ≥30°C, suggest "Wear light clothes."
b. If 20°C ≤ temperature < 30°C, suggest "Wear moderate clothing."
c. If temperature < 20°C, suggest "Wear warm clothes."
temperature = int(input("Enter temperature in °C: "))
if temperature >= 30:
print("Wear light clothes.")
elif temperature >= 20 and temperature < 30:
print("Wear moderate clothing.")
else:
print("Wear warm clothes.")
Output:
Enter temperature in °C: 25
Wear moderate clothing.
3. Implement a discount system for an e-commerce website.
a. If the total purchase is ≥Rs5000, apply a 20% discount.
b. If Rs2000 ≤ total < Rs5000, apply a 10% discount.
c. If total < Rs2000, no discount is applied.
total = float(input("Enter total purchase amount (Rs): "))
if total >= 5000:
discount = total * 0.20
elif total >= 2000 and total < 5000:
discount = total * 0.10
else:
discount = 0
final_amount = total - discount
print("Discount Amount: Rs", discount)
print("Final Amount to Pay: Rs", final_amount)
Dept. of CSE, SPT-Tumakuru 2
Output:
Enter total purchase amount (Rs): 2800
Discount Amount: Rs 280.0
Final Amount to Pay: Rs 2520.0
4. Create a program that simulates an ATM machine to check:
a. If the entered PIN is correct, allow the user to proceed.
b. Validate that the withdrawal amount doesn’t exceed the account balance.
c. Ensure that the withdrawal amount is in multiples of a specific denomination
(e.g., Rs100).
correct_pin = 1234
balance = 10000
pin = int(input("Enter your PIN: "))
if pin != correct_pin:
print("Incorrect PIN.")
else:
print("PIN verified successfully.")
amount = int(input("Enter withdrawal amount: "))
if amount > balance:
print("Insufficient balance.")
elif amount % 100 != 0:
print("Amount should be in multiples of Rs100.")
else:
balance = balance – amount
print("Withdrawal successful.")
print("Remaining Balance: Rs", balance)
Output:
Enter your PIN: 1234
PIN verified successfully.
Enter withdrawal amount: 5600
Withdrawal successful.
Remaining Balance: Rs 4400
Dept. of CSE, SPT-Tumakuru 3