Tennessee Lottery’s Powerball game

 

Background Information
In the Tennessee Lottery’s Powerball game1
, each ticket costs $2 and consists of two parts:
• Five distinct integers (i.e., no duplicates) between 1-69, inclusive
• One integer (the “Powerball number”) between 1-26, inclusive. The Powerball number may
or may not coincide with one of the previously chosen numbers.
1https://tnlottery.com/games/how-to-play/powerball/
1
A ticket wins the jackpot if all five distinct numbers plus the Powerball number match the randomly
drawn numbers. The matching of the five distinct numbers is done without regard to order. For
example, a ticket with 54, 49, 3, 18, and 20 matches drawn numbers of 3, 54, 18, 20, and 49.
In math, the set of five distinct numbers chosen by the player is known as a combination. The
number of possible combinations of k items chosen from a set of n items is usually written as
n
k

(pronounced “n choose k”) and is computable using this formula:

n
k

=
n!
k!(n − k)! (1)
Calculating the factorials in the formula directly is not an efficient way to find n choose k. This
is because the factors in (n − k)! cancel some of the factors in n!, so there’s no need to compute
those cancelled factors at all. A more efficient way to compute n choose k is this:

n
k

=
n × (n − 1) × (n − 2) × … × (n − k + 1)
k!
(2)
The number of possible Powerball tickets can be computed by letting k = 5 (the player chooses
5 numbers), n = 69 (each of those numbers ranges from 1 to 69), and multiplying the result of n
choose k by 26 (the quantity of possible Powerball numbers):
Number of possible tickets = 26
69
5

= 26 × 11, 238, 513 = 292, 201, 338
A single ticket’s chance of winning the jackpot is thus 1 in 292,201,338. To put that in perspective, suppose you net $1,000,000 from the sale of your Harbor Town mansion, and you use the
proceeds to buy Powerball tickets. Since tickets cost $2 each, this allows you to buy 500,000 tickets.
Even with that many, your chances of winning the jackpot are a miserably low 500,000/292,201,338,
which is about 0.17%. Makes you think twice about buying that ticket, doesn’t it?
Note that the structure of the Powerball game (the ranges of numbers) has changed over time2
.
In general, for a lottery game that involves picking k distinct numbers from a set of n numbers,
plus one of m bonus numbers, we can compute the number of possible tickets like this:
Number of possible tickets = m

n
k

(3)
Project Specifications
This project involves writing a simulation of a lottery game. The game settings (i.e., the values of
k, n, and m above) can be chosen by the player. Once the game has been configured, the player can
buy as many tickets as they want. The program then simulates a drawing and shows the player’s
best ticket(s) (i.e., the ticket or set of tickets that comes closest to winning the jackpot), and it lets
2See https://en.wikipedia.org/wiki/Powerball#Playing_the_game for a history of this. Unsurprisingly, the
chance of winning the jackpot has gone down over time…
Page 2 of
the player know whether they’ve won. Although the real Powerball game offers several lesser prizes
for matching a portion of the numbers, we’ll ignore those for this project – it’s all or nothing!
All of your code for this assignment should be within a single file named lottery.py. To help
you with code organization (and to make the TAs’ grading job easier), your project must contain
the functions below. You’re also welcome to add other functions if you like. Be sure to include
comments before each function summarizing what it does!
You may assume that arguments to all functions are valid. However, some of the functions that
involve reading user input ask you to validate that user input.
1. (10 points) num possible tickets(k, n, m)
Returns the number of possible tickets in a lottery game that involves choosing k distinct
integers from 1 to n (inclusive), plus one bonus integer from 1 to m (inclusive). Use equation
(3) to compute this, and use the efficient technique of equation (2) when computing the value
of n choose k.
2. (20 points) get player numbers(k, n)
Gets user input for k distinct integers between 1 and n (inclusive). The results should be
returned in a 1D list of length k. Include input validation with loops to ensure that each
input is not outside the range 1 to n, and also does not duplicate any previously entered value.
Different error messages should be shown in each of these two scenarios.
3. (5 points) get player bonus(m)
Gets user input for and returns a single integer between 1 and m (inclusive). Include input
validation with a loop to ensure that the user input is not outside the range 1 to m.
4. (10 points) get drawn numbers(k, n)
Randomly generates k distinct integers between 1 and n (inclusive). The results should be
returned in a 1D list of length k.
5. (5 points) get drawn bonus(m)
Randomly generates and returns a single integer between 1 and m (inclusive).
6. (5 points) print ticket(list distinct, bonus)
Prints the single lottery ticket consisting of the distinct numbers in list distinct and the
specified bonus number. This function should only print this information; it does not return
anything. You can be as simple or as fancy as you want with the formatting!
7. (5 points) count matches(list a, list b)
Returns the quantity of elements in list a that also appear in list b. You may assume that
both lists contain distinct elements. Here are some example arguments for this function and
their expected return values:
list a list b Return Value
[1, 2, 3] [3, 1] 2
[1, 2, 3] [5, 7, -1] 0
Page 3 of 7
8. (40 points) Below all your function definitions, the main program should tie everything together. Call your previously written functions as necessary. Here’s a summary of what the
main program should do:
• Get user input for how to set up the lottery game (i.e., get values for k, n, and m). Include
input validation with loops to ensure that k ≥ 1, n ≥ k, and m ≥ 1.
• Show how many possible tickets exist for that game, and a single ticket’s chance of winning
the jackpot.
• Get user input for t, how many tickets to buy. Include input validation with a loop to
ensure that t ≥ 1.
• For each ticket, get user input for the k distinct numbers to play and the corresponding
bonus number. The distinct numbers should be stored into a 2D list containing t rows
and k columns; each row stores the numbers chosen for one ticket. The bonus numbers
should be stored into a 1D list of length t. After each ticket has been entered, show all of
the tickets that have been entered so far.
• Once all tickets have been entered, simulate the lottery drawing.
• Find and show the “best” ticket(s). The “best” ticket is the one that matches more of
the k distinct numbers than any other ticket. Matching the bonus number is used as a
tiebreaker. For example, in a game that involves selecting 3 distinct numbers, here’s a
hierarchy of possible tickets from best to worst:
– All 3 numbers match, plus the bonus number (this wins the jackpot)
– All 3 numbers match, without the bonus number
– 2 of 3 numbers match, plus the bonus number
– 2 of 3 numbers match, without the bonus number
– 1 of 3 numbers match, plus the bonus number
– 1 of 3 numbers match, without the bonus number
– 0 of 3 numbers match, and the bonus number matches
– 0 of 3 numbers match, and the bonus number doesn’t match
In case two or more tickets tie for “best,” show all of them.
• For the best ticket(s), show how many of the k distinct numbers match the drawn numbers,
whether the bonus number matches, and whether the jackpot was won. To win the jackpot,
all k distinct numbers and the bonus number must match the drawn numbers.
The next pages have an example of how your completed program might look when running.

Sample Solution

wever Fielder’s description of how situational factors affect the leadership style required for the situation is extremely useful in understanding the fundamentals of leadership (Pettinger, 2007). Chelladurai in his Multi Dimensional Model of Leadership, expands on much of Fiedler’s theory but in a continuum based approach, in which the leader can adapt their leadership style to fit the situation (Chelladurai and Madella, 2006). Chelladurai’s theory is taken from sports psychology but can be applied to an organisational scenario. It provides a much more empirical categorisation of task structure, clearly differentiating a plethora of situations that require certain leadership styles for success. Chealldurai found three characteristics that affect the leadership style required for a situation, called antecedents, they mainly expand upon Fiedler’s situational factors and leader – member relations and ultimately affect how a leader should behave towards a situation. The first are situational characteristics, the environment in which the leader must perform, the second are leader characteristics, the experience, personal qualities and skills of the leader, and the third are member characteristics, the motivation, skill and experience levels of group members (Chelladurai and Madella, 2006). The situational characteristics and member characteristics have a required behaviour to ensure maximum group performance, they also have a preferred behaviour to ensure the satisfaction of group members, if the leaders actual behaviour matches both the required behaviour and preferred behaviour of the situation the consequence is maximum group performance and satisfaction. However, if the group are not performing and achieving goals or are not satisfied or both, then the leader is able to amend their actual behaviour to improve this. Leaders able to monitor performance and satisfaction, and understand what is required to amend the situation will achieve optimum group performance in Chelladurai’s model.
The one limitation of Chealldurai’s model is that it assumes the leader is in a position of complete positional power over the group, and can implement any leadership style of their choosing without constraints. Positional power is the authority and influence a leader has over a group, if the leader has positional power, they will be able to implement the leadership style they best see fit for the situation. Positional power cannot be measured or quantified, making it highly ambiguous and hard for a leader to understand whether they have it or how then can gain it. It becomes the responsibility of the organisation to have policies in place to provide leaders with some positional power, usually by establishing a clear hierarchal structure. By establishing a hierarchy, the leader is perceived by the group to be able to make demands and expect compliance from them giving the leader legitimate power (French and Raven, 1959). Secondly, by providing the leader with the ability to reward compliance and punish non compliance from the group, the leader has reward and coercive power (French and Raven, 1959). To obtain complete power over the group the leader must gain the trust and belief of the group that they are capable of success, by ensuring the group are both satisfied and meeting performance goals.

This question has been answered.

Get Answer
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
👋 Hi, Welcome to Compliant Papers.