Ppl Practical
Ppl Practical
class ShoppingCart:
def __init__(self):
self.cart = {}
self.prices = {"apple": 10, "banana": 5, "milk": 50, "bread": 30, "eggs": 60}
def display_products(self):
print("\nAvailable Products:", *[f"{p.capitalize()}: ₹{pr}" for p, pr in
self.prices.items()], sep="\n")
def add_to_cart(self, product, quantity):
if product in self.prices:
self.cart[product] = self.cart.get(product, 0) + quantity
print(f"{quantity} x {product} added to your cart.")
else:
print(f"Sorry, {product} is not available.")
def remove_from_cart(self, product):
print(f"{product} {'removed' if self.cart.pop(product, None) else 'not in your cart'}.")
def view_cart(self):
if not self.cart:
print("\nYour cart is empty.")
else:
total = sum(self.prices[p] * q for p, q in self.cart.items())
print("\nYour Cart:", *[f"{p.capitalize()} x {q} = ₹{self.prices[p] * q}" for p, q in
self.cart.items()], f"Total: ₹{total}", sep="\n")
def generate_bill(self):
if not self.cart:
print("\nYour cart is empty. No bill to generate.")
else:
self.view_cart()
print("Thank you for shopping with us!")
def main():
cart = ShoppingCart()
options = {"1": cart.display_products, "2": lambda: cart.add_to_cart(input("Product:
").lower(), int(input("Quantity: "))),
"3": lambda: cart.remove_from_cart(input("Product to remove: ").lower()), "4":
cart.view_cart,
"5": cart.generate_bill}
while True:
print("\n1. View Products\n2. Add to Cart\n3. Remove from Cart\n4. View Cart\n5.
Generate Bill\n6. Exit")
choice = input("Enter your choice: ")
if choice == "6": break
options.get(choice, lambda: print("Invalid choice."))()
if __name__ == "__main__":
main()
2.product = {}
print("Menu:\n1. Add Product\n2. Remove Product\n3. Update Product\n4. Display
Products\n5. Quit")
while True:
try:
choice = int(input("\nEnter your choice: "))
if choice == 1:
name, price, qty = input("Product name: ").strip(), float(input("Price: ")),
int(input("Quantity: "))
product[name] = {'price': price, 'quantity': qty}
print(f"{name} added!")
elif choice == 2:
name = input("Product to remove: ").strip()
print(f"{name} {'removed' if product.pop(name, None) else 'not found'}!")
elif choice == 3:
name = input("Product to update: ").strip()
if name in product:
price, qty = float(input("New price: ")), int(input("New quantity: "))
product[name] = {'price': price, 'quantity': qty}
print(f"{name} updated!")
else:
print(f"{name} not found!")
elif choice == 4:
if product:
print("\nProducts:")
total_price = 0
for name, details in product.items():
total = details['price'] * details['quantity']
total_price += total
print(f"{name} | Quantity: {details['quantity']} | Price: ₹{details['price']} | Total:
₹{total}")
print(f"\nTotal Price of all products: ₹{total_price}")
else:
print("No products to display.")
elif choice == 5:
print("Goodbye!")
break
else:
print("Invalid choice!")
except ValueError:
print("Enter a valid number.")
3.def vacation_decision_maker():
print("Welcome to the Vacation Destination Decision Maker!")
print("Answer the following questions to find your ideal vacation spot.\n")
climate = input("Do you prefer a warm, cold, or moderate climate?
(warm/cold/moderate): ").strip().lower()
activity = input("What type of activities do you enjoy? (adventure/relaxation/culture):
").strip().lower()
budget = input("Is your budget high, medium, or low? (high/medium/low):
").strip().lower()
if climate == "warm" and activity == "adventure" and budget in ["medium", "high"]:
destination = "Hawaii"
elif climate == "cold" and activity == "relaxation" and budget == "medium":
destination = "Switzerland"
elif climate == "moderate" and activity == "culture" and budget == "low":
destination = "Greece"
elif climate == "warm" and activity == "relaxation" and budget == "low":
destination = "Thailand"
elif climate == "cold" and activity == "adventure" and budget in ["medium", "high"]:
destination = "Canada"
elif climate == "moderate" and activity == "adventure" and budget in ["medium",
"high"]:
destination = "New Zealand"
else:
destination = "a staycation, as no match was found."
print(f"\nBased on your preferences, we recommend {destination} for your next
vacation!")
vacation_decision_maker()