Write a python program that will simulate the NJ Cash 5 lottery. The program mus
ID: 3816467 • Letter: W
Question
Write a python program that will simulate the NJ Cash 5 lottery.
The program must pick 5 numbers from 1 to 38 - No duplicates allowed
It must print these numbers side by side on one line under the heading "These are the cash 5 numbers."
You will need to "import random" at the beginning of your code similar to the challenge at the end of chapter 5
After selecting the 5 numbers, ask the user if they want to play again and allow them to do so.
This will require nested loops and lists (arrays).
I need help with this code.
Explanation / Answer
# paste bin link for code with indentation: https://pastebin.com/NwBAQPnw
import random
def get_nj_lottery_numbers():
return random.sample(range(1, 39), 5)
def play_nj_cash_5_lottery():
lottery_num = get_nj_lottery_numbers()
print("These are the cash 5 numbers: "),
for num in lottery_num:
print(num),
print("")
def main():
while(True):
play_nj_cash_5_lottery()
playAgain = raw_input("Play again? Yes/No : ")
if playAgain.lower() == "no":
break
if __name__ == "__main__":
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.