Question

In: Computer Science

Can I have this answer in a screenshot of the python software? In the game of...

Can I have this answer in a screenshot of the python software?

In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4; otherwise, the player loses $1. Suppose that, to entice the gullible, a casino tells players that there are many ways to win: (1, 6), (2, 5), and soon. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many people's eyes glaze over at the first mention of mathematics “wins $4”.

      Your challenge is to write a program that demonstrates the futility of playing the game. Your Python program should take as input the amount of money that the player wants to put into the pot, and play the game until the pot is empty.

            The program should have at least TWO functions (Input validation and Sum of the dots of user’s two dice). Like the program 1, your code should be user-friendly and able to handle all possible user input. The game should be able to allow a user to ply as many times as she/he wants.

            The program should print a table as following:

      Number of rolls            Win or Loss                 Current value of the pot

                  1                                 Put                                    $10

                  2                                 Win                                  $14

                  3                                 Loss                                  $11

                  4

                  ##                              Loss                                  $0

        You lost your money after ## rolls of play.

        The maximum amount of money in the pot during the playing is $##.

        Do you want to play again?

      At that point the player’s pot is empty (the Current value of the pot is zero), the program should display the number of rolls it took to break the player, as well as maximum amount of money in the pot during the playing.

        Again, add good comments to your program.

        Test your program with $5, $10 and $20.

Solutions

Expert Solution

import random


def validate_input(money):
    # If money is 0, return false else true
    if money <= 0:
        return False
    else:
        return True


def roll_dice():
    # Roll dice twice and return their sum
    dice1 = random.randint(1, 6)
    dice2 = random.randint(1, 6)
    return dice1 + dice2


if __name__ == '__main__':

    choice = 'y'
    # Iterate loop till choice is y or Y
    while choice.lower() == 'y':
        # Ask user to enter money they want to put
        # Validate input. If false, print invalid input else continue with program
        money = int(input('Enter the amount of money you want to put in the pot: '))
        if validate_input(money) is False:
            print('Invalid input!')
        else:
            # Print column header
            print("\n%-20s%-20s%-20s" % ("Number of rolls", "Win or Loss", "Current value of the pot"))
            # Set, rolls = 1, win_or_loss = "Put" and maximum_money  = money intially
            # Print the values
            rolls = 1
            win_or_loss = "Put"
            maximum_money = money
            print("%-20d%-20s$%-20d" % (rolls, win_or_loss, money))
            # Iterate while loop till money > 0
            # call function and
            # if returned value is = 7, set win_or_loss to Win and add 4 to money
            # else, set win_or_loss to Loss and subtract 1 from money
            while money > 0:
                if roll_dice() == 7:
                    win_or_loss = "Win"
                    money += 4
                else:
                    money -= 1
                    win_or_loss = "Loss"

                # Increment rolls by 1
                rolls += 1

                # If maximum_money < money, set maximum_money  = money
                if maximum_money < money:
                    maximum_money = money

                # Print current values
                print("%-20d%-20s$%-20d" % (rolls, win_or_loss, money))

            # After the inner loop, print total rolls and maximum_money
            print('\nYou lost your money after %d rolls of play.' % (rolls))
            print('The maximum amount of money in the pot during the playing is $%d' % (maximum_money))
        # Ask user if they want to play again
        choice = input('\nDo you want to play again? (y/n) ')
        print()

SCREENSHOT


OUTPUT


Related Solutions

Can I get this logic in Python? plus what software I can use it to run?...
Can I get this logic in Python? plus what software I can use it to run? thanks and will rate!!! Search Lab implement the following logic in Python, use appropriate data types. Data types are represented as either numeric (num) or string. string name string address num item num quantity num price num SIZE = 6 num VALID_ITEM [SIZE] = 106, 108, 307, 405, 457, 688 num VALID_ITEM_PRICE [SIZE] = 0.59, 0.99, 4.50, 15.99, 17.50, 39.00 num sub string foundIt...
can i just screenshot the data i used GSS to find and extracf the data
can i just screenshot the data i used GSS to find and extracf the data
I have to answer these questions in a way that I can write out in a...
I have to answer these questions in a way that I can write out in a word document. Previous answer make little sense. I need to interpret (A) and I am just not understanding what the y intercept of -23 is indicating. I understand question b, not 100% on C please see below:   A criminologist is interested in the effects of unemployment and policing on murder and has run the following multiple regression: Summary Output Regression Statistics Multiple R 0.90303...
I am new to python, and i used python 3. i have to make a new...
I am new to python, and i used python 3. i have to make a new program can anyone give tell mw how to do this. A) Write a function with the name doubler. The function should take an integer parameter and return twice the value of the integer. Test the function with the following code: print(“Double of 6 is”,doubler(6)) The printout should be: Double of 6 is 12 B) Write a function with the name scoreToLetter. The function should...
I want to understand how this can be solved in c++. Please send a screenshot also...
I want to understand how this can be solved in c++. Please send a screenshot also with your code so I can see how it is supposed to be formatted or indented. Instructions: Your program will read in a file of commands. There are three types of commands: Warrior creates a new warrior with the specified name and strength. Battle causes a battle to occur between two warriors. Status lists all warriors, alive or dead, and their strengths. A sample...
Can I have a reference and intext citation of the software SAS university edition & SAS...
Can I have a reference and intext citation of the software SAS university edition & SAS 9.4 please thank you
PYTHON Exercise 4. Fantasy Game Inventory Imagine you have this inventory in a fantasy game: Item...
PYTHON Exercise 4. Fantasy Game Inventory Imagine you have this inventory in a fantasy game: Item Number of this items Rope 1 Torch 6 Gold coin 42 Dagger 1 Arrow 12 1. Save the inventory in a data structure. 2. Write a function that will take any possible inventory and display it in a pretty format. 3. Write a function to add new items to the data structure. Make sure new group of items can be created. 4. Write a...
Please in C++ thank you! Please also include the screenshot of the output. I have included...
Please in C++ thank you! Please also include the screenshot of the output. I have included everything that's needed for this. Pls and thank you! Write a simple class and use it in a vector. Begin by writing a Student class. The public section has the following methods: Student::Student() Constructor. Initializes all data elements: name to empty string(s), numeric variables to 0. bool Student::ReadData(istream& in) Data input. The istream should already be open. Reads the following data, in this order:...
In python using tkinter, I want to create a program. The program can have various classes...
In python using tkinter, I want to create a program. The program can have various classes and methods but I want it to have circles, triangles, and squares. Each shape movies in a certain way, like circles can move linearly, triangles can be affected by gravity, and squares can only go up and down. If the shapes get too close to one another then they disappear and a new shape appears somewhere else. I want this program to run continuously.
PYTHON GAME OF PIG The game of Pig is a simple two player dice game in...
PYTHON GAME OF PIG The game of Pig is a simple two player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn a player rolls a six-sided die. After each roll: a) If the player rolls a 1 then the player gets no new points and it becomes the other player’s turn. b) If the player rolls 2-6 then they can either roll again or hold. If the player...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT