Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

Official Powerball number generator How many sets of numbers? 5 Your numbers 15 25 33 40 46 Powerball: 22 Your numbers: 2 8 25 32 38 Powerball: 30 Your numbers: 3 17 18 24 49 Powerball: 10 Your numbers 20 27 34 46 48 Powerball: 23 Your numbers: 20 27 28 34 42 Powerball: 11

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))
  
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote