The first five numbers are drawn from a drum containing 53 balls and the sixth i
ID: 3818839 • Letter: T
Question
The first five numbers are drawn from a drum containing 53 balls and the sixth is drawn from a drum containing 42 balls. The chances of doing this are 1 in 120,526,770. Write a program (IN PYTHON) to generate a set of Powerball numbers by utilizing the choice function in Python's random module.
Part 1 - Powerball Number Generator
Input: Ask the user how many sets of Powerball numbers he or she would like.
Output: The program will print each set of Powerball numbers in numeric order.
Part 2 - Powerball Number Predictor
Execute your Powerball number generator 10,000 times and write a simple script printing out the top five most frequently appeared numbers and the Powerball.
Explanation / Answer
# link for code in case indetation is messed up: https://pastebin.com/HvBHvGRv
import random
def powerBallGenerator(n):
for i in range(0, n):
numbers = random.sample(range(1,54), 5)
numbers = [str(i) for i in numbers]
powerBall = random.choice(range(1, 43))
print("Your numbers: " + " ".join(numbers) + " Powerball: " + str(powerBall))
print("Official Powerball number generator")
n = int(input("How many sets of numbers? "))
powerBallGenerator(n)
Part2:
# Pastebin code link: https://pastebin.com/Rr5Cixhi
import random
from collections import Counter
def powerBallGenerator():
numbers = random.sample(range(1,54), 5)
powerball = random.choice(range(1, 43))
return (numbers, powerball)
def powerBallPredictor(n):
count_list = {}
powerBall_list = {}
for i in range(0, n):
(numbers, powerball) = powerBallGenerator()
if powerball in powerBall_list:
powerBall_list[powerball] += 1
else:
powerBall_list[powerball] = 1
for num in numbers:
if num in count_list:
count_list[num] += 1
else:
count_list[num] = 1
d = Counter(count_list)
numbers = []
for k, v in d.most_common(5):
numbers.append(k)
powerball = max(powerBall_list.iterkeys(), key=lambda k: powerBall_list[k])
return (numbers, powerball)
(numbers, powerball) = powerBallPredictor(10000)
numbers = [str(i) for i in numbers]
print("Most prequent numbers: " + " ".join(numbers) + " Powerball: " + str(powerball))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.