Showing posts with label lucky friend. Show all posts
Showing posts with label lucky friend. Show all posts

Monday, November 25, 2024

Party Bill Split with Lucky Friend Feature

The task is to simulate a party scenario where a group of friends, including the user, attend a party. The program calculates and divides the total bill among the friends, with an option for one friend to be lucky, meaning they don’t have to pay. The program asks for inputs to gather information about the number of people attending, their names, and the total bill. It also includes a feature where a random "lucky friend" can be selected, who will not pay for the party.

### Solution Explanation

1. **Input Phase:**
   - **Number of Friends:** The program asks the user to enter the number of friends attending the party (including the user). If no one is attending, the program will inform the user and exit.
   - **Friends' Names:** After the number of attendees is entered, the program requests the names of each person attending the party.
   - **Total Bill:** The program then asks for the total amount of the bill to be paid by the group.

2. **Lucky Feature:**
   - The user is given the option to enable the "lucky friend" feature. If the user chooses "Yes", the program randomly selects one person to be the "lucky friend", and this person will not have to contribute to the bill. 
   - If the user chooses "No", the bill is divided evenly among all attendees.

3. **Bill Calculation:**
   - **With Lucky Friend:** If the "lucky friend" feature is activated, the bill is divided among the remaining friends (excluding the lucky one). The lucky friend’s contribution is set to 0.
   - **Without Lucky Friend:** If the feature is not enabled, the bill is divided evenly among all attendees.

4. **Output:**
   - The program outputs a dictionary where each friend's name is mapped to the amount they need to pay. The lucky friend will have a bill of 0 if the "lucky" feature is enabled.

### Example Scenario

- **Input:**
  - The user enters `4` as the number of people joining the party.
  - The names of the friends are entered as: Alice, Bob, Charlie, and Dave.
  - The total bill is `100`.
  - The user opts to use the "Who is lucky?" feature and selects "Yes".

- **Output:**
  - A random person, say "Charlie", is selected as the lucky one.
  - The bill for the other 3 friends (Alice, Bob, and Dave) is divided equally:
    - Total bill = `100`
    - Amount per person (excluding the lucky friend) = `100 / 3 = 33.33`
  - The output dictionary might look like this:
    
    {'Alice': 33.33, 'Bob': 33.33, 'Charlie': 0, 'Dave': 33.33}
    

### Summary:

- If the "lucky" mode is enabled, one friend gets selected randomly to not pay for the party.
- The remaining friends split the total bill.
- If no one is lucky, everyone shares the bill equally.
- The solution handles cases where no one is attending, and it ensures the calculation is correct regardless of whether the lucky mode is enabled.

Featured Post

How HMT Watches Lost the Time: A Deep Dive into Disruptive Innovation Blindness in Indian Manufacturing

The Rise and Fall of HMT Watches: A Story of Brand Dominance and Disruptive Innovation Blindness The Rise and Fal...

Popular Posts