Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

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

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions

Question

Explain Three Disadvantages of ERP Systems.

Answered: 1 week ago