Python Forum
Write pseudo code for a class assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write pseudo code for a class assignment
#1
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.
Reply
#2
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.
Reply
#3
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} :)')
Reply
#4
(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...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write a dict code in python ariellea88 4 913 Oct-31-2023, 08:45 AM
Last Post: buran
  how to write code demon_calcifer 1 1,595 Nov-16-2021, 04:09 PM
Last Post: Larz60+
  Can someone please help me write the code Ram 8 3,250 Feb-08-2021, 08:21 AM
Last Post: Serafim
  Stein's GCD according to given pseudo code wanttolearn 2 1,920 Aug-27-2020, 07:58 PM
Last Post: wanttolearn
  Please help me to write code for this vij 8 3,704 Jun-10-2020, 12:13 PM
Last Post: pyzyx3qwerty
  morse code assignment raymond2688 11 8,423 Jul-29-2019, 07:43 PM
Last Post: raymond2688
  Need some help with a bit of code for an assignment. JackMercer50 1 2,251 Feb-09-2019, 04:13 PM
Last Post: stullis
  Write a code to output in alphabetical order AbdelaliPython 1 4,560 Jan-19-2018, 09:03 PM
Last Post: j.crater
  NEED HELP Pseudo-Random Numbers Kongurinn 9 5,342 Oct-23-2017, 04:17 AM
Last Post: Skaperen
  pseudo code for a quiz tsaward 4 7,629 Sep-15-2017, 09:59 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020