Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Powerball List
#1
So I need to make a power ball list heres the details

Write a program that simulates a mini game of powerball. In this game, a ticket consists of 3 unique numbers between 1 and 9 and a 4th 'powerball' number between 1 and 3. A random drawing is done and the winnings are as follows:

One correct number wins $1, two numbers correct wins $10, three correct numbers win $100. If the Powerball number is correct, it multiplies the winnings by 2, unless all three numbers and the Powerball number are correct, in that case, a jackpot of $1000 is won.


So I have the code that allows me to enter the statements but my issue is I can't seem to figure out how to edit it so that I can change it to set number for each input like I need my 1-3 inputs to be set choices of 1,9 and my 4th input to be a set choice of 1,3 but I don't even see any way to edit that part and theres no print statements to edit the list names there all just number 1 number 2 number 3 and number 4 so any advice on that would really help me so I can finish this program thanks





 numbers = [] 


for i in range(1,5): 
    num = int(input("Enter number" + str(i)+": "))
    while num in numbers:
        print("The number must be unique, try again")
        num = int(input("Enter number" + str(i)+": "))
    numbers.append(num)


print("The numbers were:",end=" ")
for num in numbers:
    print(num,end=" ")
print()



numbers = [] 


for i in range(1,5): 
    num = int(input("Enter number" + str(i)+": "))
    while num < 1 or num > 10:
        print("The number must be between 1 and 10, try again")
        num = int(input("Enter number" + str(i)+": "))       
    numbers.append(num)


print("The numbers were:",end=" ")
for num in numbers:
    print(num,end=" ")
print()
Reply
#2
Your code is forcing the powerball number to also be unique and it is checking the powerball against the range 1..10. Shouldn't that range be 1..9 for the first three numbers and 1..3 for the powerball?

Since the powerball requirements are different than the requirements for the first three numbers, I don't think you want to do this with just one loop. You already have a loop that will give you 4 unique numbers in the range from 1..10. I bet you can figure out how to fix that so it is three numbers in the range 1..9. When prompting for a number you probably want to tell the user they need to enter a unique numbers in the range of 1..9. You could put this in the prompt, or display a message if they make an error (if num in numbers: print(num, 'is already used') or (if num < 1 or num > 9): print('Numbers must be in the range 1..9').

For the powerball all you need is a number between 1 and 3. You already know how get a number from the user and check against some range. You even know how to add the number to a list. Again, I bet you can figure out how to get a number between 1 and 3 and append it to the end of your numbers list.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Powerball assignment, how to get correct output of a dictionary ? msp1981 5 3,268 Mar-19-2019, 11:02 PM
Last Post: Yoriz
  Powerball script help nick 6 6,996 Nov-11-2016, 07:56 PM
Last Post: micseydel
  PowerBall Help nick 3 4,762 Nov-11-2016, 06: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