Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON CODE ! NEED URGENTLY !! DUE TODAY!! Please make sure you provide good and quality code. Run your code in python compiler or execute

PYTHON CODE ! NEED URGENTLY !! DUE TODAY!!

Please make sure you provide good and quality code. Run your code in python compiler or execute it online to match output as specified.

Must follow proper indentation! Don't post incorrect code to block this question.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Thanks in Advance! Do write your code in Notepad++ for proper indentation and format.

Chuck-a-luck is a gambling dice game found in some casinos. We'll simulate the game (though not all of the betting combinations). For more information on chuck-a-luck, see the Wikipedia article, Setup Create a Python file called hw06.py Your hw06.py file must begin with comments in the following format (replace the name and email with your actual information) Name SE 150, Spring 2019 USC email Homework 6 Requirements The assignment is broken into several parts - and it is recommended that you proceed in the order given Part 1: Setup . We will use several functions to play this game. For now, create the following 3 functions with no implementation (just the function header and empty function "guts") o "rol1"- Accepts no input Returns a list of 3 integers holding the results of the dice rolls . o "computeBetResult" Accepts 3 pieces of input (you may name the input anything you'd like) . The integer list containing the 3 numbers representing the dice rolls A single integer containing the amount the user bet A single integer holding the number the user "guessed" . Returns a single integer representing the amount of money the user won For now, in its body, have it return 0 o "main" . This is our regular main. It should be called by your overall program Make sure your code runs before moving on to the next step Part 2: User interface Create a variable to hold the user's "money" -initialize it to 100 Introduce the user to your game, announce how much money they have, and ask for an amount to bet (which you should store in another integer variable) o Make sure this bet is valid. A valid bet is greater than 0 and less than or equal to the total amount of money the user has. If the user enters an invalid bet, tell the user what the valid betting range is and prompt them again. Ask the user for a number to bet on. o Make sure the number is valid. Valid numbers are 1, 2, 3,4, 5, and 6. If the user enters an invalid number, tell the user the proper range and ask for another number Summarize and repeat (via the console) the user's decisions . Leave some space in main after this point, we'll return here in a bit. . We'll now call our empty (or "stubbed") functions. First we'll "roll" the dice. The purpose of the roll function is to make a list with three random numbers from 1 to 6. Call that function. For now, it will do nothing, but we'll fill in functionality soon. . The function computeBetResults will determine the user's winnings and return the money won or lost. For now, call that function giving it o The dice list o The amount of money the user bet o The number the user bet on . The function computeBetResults will determine the user's winnings and return the money worn or lost. For now, call that function giving it o The dice list o The amount of money the user bet o The number the user bet on Store the results of the function call in an integer For now, the results of the computeBetResults will always be 0, but eventually it will be a positive number or negative their bet amount if they lost. If it's positive, then the user won the wager. Congratulate the user and add the winnings to the user's total. If the number is negative, the user lost the bet, encourage the user to try again Tell the user their new money total Ask the user if they'd like to play again. If the user enters "N" or "n, stop the game. The game should also stop if the user runs out of money Output for Part 2 should look something like this (user input in red) STEP RIGHT UP AND PLAY SOME CHUCK-A-LUCK! You have $100 Enter a bet amount: $20 What number do you want to bet on (1-6)? 3 You bet $20 on 3 You rolled You lost your bet :( You now have $80 Would you like to play again (y)? y Enter a bet amount: $100 Invalid bet. Please enter an amount from $1 to $80 Enter a bet amount: $7 What number do you want to bet on (1-6)? 7 Invalid number. Must be between 1 and 6 What number do you want to bet on (1-6)? 1 You bet $7 on 1 You rolled You lost your bet :( You now have $73 Would you like to play again (y)? n You ended the game with $73 Part 3: Die rolling The function roll generates three random numbers between 1 and 6. To do that we'll use functions in the random module of Python- so be sure to import it. Use the randrange function of random to generate a random number between 1 and 6. Call that function 3 times and store all the results in the inputted list. You could just loop over the entire list and replace each number, but it's up to you to decide how best to do this part. When you get roll working, test it for a bit. Test it by calling print on the list in main. If you've got it working right, you'll get a different set of values each time. .Please note how to display the rolls (Hint: you can't print the list directly) Once you've completed Part 3, your program output should resemble the following (user input in red): STEP RIGHT UP AND PLAY SOME CHUCK-A-LUCK! You have $100 Enter a bet amount: $21 What number do you want to bet on (1-6)? 4 You bet $21 on 4 You rolled: 5, 3, 1 You lost your bet : You now have $79 Would you like to play again (y)? y Enter a bet amount: $50 What number do you want to bet on (1-6)? 6 You bet $50 on 6 You rolled 2, 2, 3 You lost your bet :( You now have $29 Would you like to play again (y)? n You ended the game with $29 Part 4: Computing bet results . Just to review, the function computeBetResult accepts the following input: o A list of integers (containing the dice rolls) o A single integer (containing the amount the user bet) o A single integer (containing the number the user bet on) Go through the inputted dice rolls and determine how many times the bet upon number occurs It should be a number between 0 and 3 Announce to the user how many dice they've matched The function should return the payout based on how many times the user's number showed up on the dice o If the number occurred 0 times, the payout is O. You should return negative their bet amount as they lost that money o If the number occurred 1 time, payout is 1 times the amount of money the user bet (plus their original bet amount) o If the number occurred 2 times, payout is 3 times the amount of money the user bet (plus their original bet amount) o If the number occurred 3 times, payout is 10 times the amount of money the user bet (plus their original bet amount) Calculate the proper payout and return that value After completing part 4, your program output should resemble the following (user input in red) STEP RIGHT UP AND PLAY SOME CHUCK-A-LUCK! Enter a bet amount: $20 What number do you want to bet on (1-6)? 1 You bet $20 on 1 You rolled 6, 4, 5 You matched dice! You lost your bet :( You now have $80 Would you like to play again (y)? y Enter a bet amount: $20 What number do you want to bet on (1-6)? 5 You bet $20 on 5 You rolled 1, 5, 5 You matched 2 dice! YOU WIN $80 You now have $140 Would you like to play again (y)? n You ended the game with $140 A Note on Style Be sure to comment your code. Also, you will lose points if your variable names are not meaningful Make sure you use variable names that correspond to what you are storing in the variables. Full Sample Output Below is sample output for a full run-through of the program. As usual, you are not required to be as descriptive as the text below, so long as you perform and display the required calculations. User input is in red STEP RIGHT UP AND PLAY SOME CHUCK-A-LUCK! You have $100 Enter a bet amount: $20 What number do you want to bet on (1-6)? 2 You bet $20 on 2 You now have $120 Would you like to play again (y)? n You ended the game with $120 Deliverables 1. A compressed folder containing hw06. Grading Item Part 1: Functions setup Part 2: User interface Part 3: Die rolling Part 4: Computing bet results Total* Points 10 25 10 15 60 *Points will be deducted for poor code style, or improper submission

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions