Nithya S’ Post

Day 7/30 🔹 Problem: Split expenses among friends (equal & custom split) 🔹 What I focused on today: Handling multiple scenarios based on user choice 🔹 My Thinking Process: Take total expense and number of people Ask user how they want to split (equal or custom) If equal → divide total by number of people If custom → take individual contributions 👉 Same problem, different approaches based on user need 🔹 Inputs I used: Total expense Number of people Choice (equal/custom) Individual amounts (for custom split) 🔹 Code: total = float(input("Enter total expense: ")) people = int(input("Enter number of people: ")) choice = input("Enter '1' for equal split or '2' for custom split: ") # Equal Split if choice == "1":   share = total / people   print("Each person should pay:", share) # Custom Split elif choice == "2":   sum_amount = 0   for i in range(people):     amount = float(input("Enter amount paid: "))     sum_amount = sum_amount + amount   if sum_amount == total:     print("Expenses match the total.")   else:     print("Amounts do not match total.") else:   print("Invalid choice") 🔹 Example: Total = 1000, People = 4 Equal → Each pays 250 🔹 Key Takeaway: Real-world problems often need flexible logic to handle different scenarios, not just one fixed solution #Day7 #Python #30DaysOfCode #LearningInPublic #DataAnalytics #ProblemSolving

To view or add a comment, sign in

Explore content categories