Python Forum

Full Version: Write pseudo code for a class assignment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here is the assignment word for word. Any help in writing this or just giving me some clues to move me along would be appreciated.


Based on a lottery winning you are required to create a pseudo code on the following criteria:

Assumption there is 1 million dollars to be won and will be split as

There are 3 tickets

6 numbers - wins jackpot, this could be shared amongst the 3 tickets

5 numbers - 40% of the winning, if there was no jackpot, and can also be shared amongst winning tickets

4 numbers 20% of 1 million, if there was no jackpot, and can also be shared amongst winning tickets

3 numbers get a free ticket for next time lottery is played.
Here is a programmer's trick: put your teddy bear in charge of organizing and running the lottery. Now explain the bear everything that it needs to do to achieve this goal and write it down.
Hi, I'm not sure how helpful it is to write the pseudocode but here's the actual python code.

from random import randint

budget = 1000000
number_of_tickets = 3

def generate_random_tickets(count = 3, mini = 0, maxi = 6):
    return [randint(mini, maxi) for _ in range(count)]

def generate_free_ticket_winnings(tickets):
    return [t == 3 for t in tickets]

def generate_money_winnings(tickets, budget):
    money_winnings = []
    
    potential_money_winnings = [
        0,0,0,0,    # nothing for 0-3
        0.2,        # 4 - 20%
        0.4,        # 5 - 40%
        1           # 6 - 100%     
        ]

    # if any ticket won the jackpot
    if 6 in tickets:
        number_of_winners = tickets.count(6)
        money_winnings = [potential_money_winnings[t] * budget / number_of_winners * (t==6) for t in tickets]
    else:
        # add up all the potential money winnings (to check if they exceed 100% and adjust budget accordingly)
        winnings_sum_of_percentages = sum(potential_money_winnings[t] for t in tickets)
        if winnings_sum_of_percentages > 1.0: # e.g. if 3 people won 40% each
            # adjust budget so all the prizes won't exceed the original one
            budget = budget / winnings_sum_of_percentages     
        money_winnings = [potential_money_winnings[t] * budget for t in tickets]                
    return money_winnings




tickets = generate_random_tickets(number_of_tickets)

money_winnings = generate_money_winnings(tickets, budget)

free_tickets = generate_free_ticket_winnings(tickets)


for t, mw, ft in zip(tickets, money_winnings, free_tickets):
    if ft:
        print(f'Ticket that scored {t} won a free ticket :)')
    elif not mw:
        print(f'Ticket that scored {t} lost...')
    else:
        print(f'Ticket that scored {t} won ${mw} :)')
(May-07-2019, 06:48 AM)Gribouillis Wrote: [ -> ]Here is a programmer's trick: put your teddy bear in charge of organizing and running the lottery. Now explain the bear everything that it needs to do to achieve this goal and write it down.

wow...