Question

Write a Python program that simulates a wheel of fortune game. The game is played as...

Write a Python program that simulates a wheel of fortune game.

The game is played as follows:

  • Spin a wheel with a group of numbers (0-10).
  • If you got a 1, 2 or a 3, the game is over.
  • If you got a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then spin again, or
  • if you got 7, 8, 9, or 10, then you win $14,$16,$18, or $20 and then spin again.
  • If you got a 0, then you lose 50% of what you won so far, but are allowed to spin again.

With each additional spin, you have the chance to win more money, or you might play the game-ending 1, 2, or 3, at which time the game is over and you keep whatever winnings you have accumulated.

Programming instructions:

  • Use the randint() function from Python's random module to get a wheel spin result (see functions for integers).
  • Run 10,000 simulations of the game.
  • Retain a win list to store your won amount for each simulation.  
  • Calculate the average amount won and the largest amount won based on your win list.
  • Comment your code where appropriate without commenting the obvious and trivial (incl. docstrings for your function).
  • Keep 2 decimals when printing the result.

Make sure your simulation is set up as a function using def () with the number of simulations as input and return the average amount won and max amount won from the simulations.
Then call that function in another part of your program and give the output formatted as shown below.

Furthermore, answer the following question in the comments of your code:

  • Would you pay $15 for a chance to play this game? Why or why not?

Example Output:

Average amount won = $xx.xx

Max amount won = $xx.xx

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

import random

def simulate(s):
    win_list = []
    max_win = 0
    sum_win = 0
    for i in range(s):
        win = 0
        
        while(True):
            n = random.randint(0,10)
            if (n in [1,2,3]):
                break
            elif (n in [4,5,6]):
                win += n
            elif (n in [7,8,9,10]):
                win += 2*n
            else:
                win = 0.5 * win
                
        win_list.append(win)
        sum_win += win
        if win > max_win:
            max_win = win
        
    return ((sum_win/s),max_win)
    
avg,m = simulate(1000)
print("Average amount won = $",format(avg,'.2f'))
print("Max amount won = $",format(m,'.2f'))
            
        
                
    

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Write a Python program that simulates a wheel of fortune game. The game is played as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C# Code: Write the code that simulates the gambling game of craps. To play the game,...

    C# Code: Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is...

  • This program should be in c++. Rock Paper Scissors: This game is played by children and...

    This program should be in c++. Rock Paper Scissors: This game is played by children and adults and is popular all over the world. Apart from being a game played to pass time, the game is usually played in situations where something has to be chosen. It is similar in that way to other games like flipping the coin, throwing dice or drawing straws. There is no room for cheating or for knowing what the other person is going to...

  • in the game of roulette, a wheel consists of the ball falls into matches the number...

    in the game of roulette, a wheel consists of the ball falls into matches the number you selected, you win $35 38 slots numbered 0, 00,1,2, 3 6. To play the game, a metal ball is spun around the wheel and is allowed to fall i otherwise you lose $1. Compiete parts (a) through (a) below nto one of the numbered slots. if the number of the slot (a) Construct a probability distribution for the random variable X, the winnings...

  • Objective: To write a program to allow a game of Tic Tac Toe to be played,...

    Objective: To write a program to allow a game of Tic Tac Toe to be played, and to determine when the game is over Complete the TicTacToe program below. It will allow for a full game of Tic Tac Toe between two players, and it will tell you who won or if the game is over with no winner. Details: The TicTacToe board is stored in a 3x3 multidimensional list of characters containing spaces at the start of the game...

  • USE PYTHON ONLY Please write a Python program to let you or the user play the...

    USE PYTHON ONLY Please write a Python program to let you or the user play the game of rolling 2 dice and win/lose money. Initially, you have 100 dollars in your account, and the dealer also has 100 dollars in his/her account. You would be asked to enter a bet to start the game. If your bet is zero, the game would be stopped immediately. Otherwise, dealer would roll 2 dice and get a number from ( random.randint(1, 6) +...

  • In the game of roulette, a wheel consists of 38 slots numbered 0.00, 1.2.36. To play...

    In the game of roulette, a wheel consists of 38 slots numbered 0.00, 1.2.36. To play the game, a metal ball is spun around the wheel and is allowed to fall into one of the numbered slots in the number of the let the ball fall into matches the number you selected, you win $35; otherwise you lose $1. Complete parts (a) through (a) below. ber t he standard nommal darbuon page 1. Sick here the standard nomadsbution table (page...

  • Please write a Python program to check a tic-tac-toe game and show its winning result in...

    Please write a Python program to check a tic-tac-toe game and show its winning result in detail. This is an application program of a 3-dimensional list or array. Your complete test run output must look as follows. This test really checks to make sure your program is performing perfectly to check every possible winning situation for X and O. GAME 0 is as follows: OOO OOO OOO O won by row 1 O won by row 2 O won by...

  • Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

    Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

  • Write a c++ program that simulates a million of games in craps. I am having a...

    Write a c++ program that simulates a million of games in craps. I am having a trouble getting to loop a million of times. I am trying to use a const for a million. This is the code so far. #include <iostream> #include <cstdlib>// contains prototypes for functions srand and rand #include <ctime>// contains prototype for function time #include <iomanip> using namespace std; int rollDice(); // rolls dice, calculates and displays sum void printstats(); int totroll = 0, games, point,...

  • Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, al...

    Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, allow the user to try up to 10 times to guess the number, and tell the user if each guess is too high, too low, or correct. The actual game portion must be a function...you can use more than one function in your program. The amount...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT