The solution should be in python and should include file format! Overview To pla
ID: 3912041 • Letter: T
Question
The solution should be in python and should include file format!
Overview
To play the PowerBall lottery, you buy a ticket that has five numbers in the range of 1–69, and a “PowerBall” number in the range of 1–26. (You can pick the numbers yourself, or you can let the ticket machine randomly pick them for you.) Then, on a specified date, a winning set of numbers is randomly selected by a machine. If your first five numbers match the first five winning numbers in any order, and your PowerBall number matches the winning PowerBall number, then you win the jackpot, which is a very large amount of money. If your numbers match only some of the winning numbers, you win a lesser amount, depending on how many of the winning numbers you have matched.
Instructions
Attached to this Dropbox, you will find a file named pbnumbers.txt, containing the winning PowerBall numbers that were selected between February 3, 2010 and May 11, 2016 (the file contains 654 sets of winning numbers). The figure below shows an example of the first few lines of the file’s contents. Each line in the file contains the set of six numbers that were selected on a given date. The numbers are separated by a space, and the last number in each line is the PowerBall number for that day. For example, the first line in the file shows the numbers for February 3, 2010, which were 17, 22, 36, 37, 52, and the PowerBall number 24.
Write a program that works with this file to perform the following:
Display the 10 most common numbers, ordered by frequency
Display the 10 least common numbers, ordered by frequency
Display the 10 most overdue numbers (numbers that haven’t been drawn in a long time), ordered from most overdue to least overdue
Display the frequency of each number 1–69, and the frequency of each Powerball number 1–26
* Consider the powerball numbers for 10 most and 10 least common numbers.
Explanation / Answer
powerball.py
from pprint import pprint as pp
import random
def powerball():
drum1 = list(range(1,70))
drum2 = list(range(1,27))
white_balls = []
for _ in range(5):
choice = random.SystemRandom().choice(drum1)
drum1.pop(drum1.index(choice))
white_balls.append(choice)
white_balls = sorted(white_balls)
return white_balls + [random.SystemRandom().choice(drum2)]
try:
budget = int(int(input('What is your powerball budget? (Number must be multiple of 2)'))/2)
except:
budget = 1
pp(list(powerball() for i in range(budget)))
Lottery.py
import random
import os
def main():
# times_to_win(lottery_numbers, power_ball)
generate_lotto_numbers(10)
def clear():
os.system('clear')
def pwr_ball():
x = random.randint(1, 26)
return x
def times_to_win(args, x):
# Call system clear
clear()
# Keep track of count
count = 1
# Infinite loop
while True:
clear()
# Display goal until user presses Enter
print("Goal Lottery Numbers: " + str(args) + " Power Ball: " + str(x))
# Grab five non-repeating random numbers from x to y
lottery_num = random.sample(range(13, 58, 1), 5)
# Add Power Ball
power_ball = pwr_ball()
# Print out current attempt
print("Attempt # " + str(count) + " - " + str(lottery_num) + " - Power Ball " + str(power_ball))
# Test if the amount of like numbers = 5
if len(set(lottery_num) & set(args)) == 5 and power_ball == x:
print("It took " + str(count) + " times to win the lottery!")
# Exit when found!
exit()
else:
count += 1
def generate_lotto_numbers(amount):
correct_amount = amount + 1
# Display lotto Numbers the ammount of times listed in the variable
for x in range(1, correct_amount):
print('Lottery Numbers: ' + str(random.sample(range(1, 70, 1), 5)) + ' - Power Ball: ' + str(pwr_ball()))
main()