Question: PYTHON 2. (game21.py) Write a program that plays the game of 21 with the user. The game consists of rounds. In each round, the user
PYTHON


2. (game21.py) Write a program that plays the game of 21 with the user. The game consists of rounds. In each round, the user is asked if they'd like to roll (2 six-sided die). If they agree, the user rolls the die and the computer rolls their die. Their rolls are added to their individual totals. The user's total is displayed at the end of each round; the computer's total is hidden. Rounds continue as long as the user indicates they would to roll and the user hasn't reached 21. Look carefully at the sample runs provided. If both computer and user exceed 21, the game is a tie. You must use two user-defined functions that meet the following specifications: Input Function Name roll_dice Processing Simulate the rolling of two dice none Output The dice roll (return two values) Refer to page 260 for information on returning multiple values. Function Name get_response Input none Output Returns valid response. Processing Prompts the user "do you want to roll?" Accepts only 'y' or 'n' as a valid response. Sample Run - the game ends because user exceeded 21 Do you want to roll? y Points: 8 Do you want to roll? y Points: 15 Do you want to roll? y Points: 22 User's points: 22 Computer's points: 20 Computer wins Sample Run - user chose to quit hoping they had won (wrong!) Do you want to roll? y Points: 9 Do you want to roll? y Points: 18 Do you want to roll? n User's points: 18 Computer's points: 20 Computer wins Sample Run - user chose to quit hoping they had won (correct this time!) Do you want to roll? y Points: 4 Do you want to roll? y Points: 8 Do you want to roll? y Points: 16 Do you want to roll? n User's points: 16 Computer's points: 30 User wins Sample Run-game ends because user hit 21 - computer exceeded 21 Do you want to roll? y Points: 10 Do you want to roll? y Points: 16 Do you want to roll? y Points: 21 User's points: 21 Computer's points: 27 User wins Sample Run - user quits before starting Do you want to roll? n User's points: 0 Computer's points: 0 Tie Game
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
