Problem Description: In this assignment, you will need to write a program that will allow the user to play a game. The program will start with showing the user a list of two games ('Guess the Number' and 'Math Challenge') and ask the user which one she/he wants to play. However, to keep the assignment manageable, you are being asked to implement only the first of these two games. If the user selects the second game, a 'technical error' message is shown, and the list of games is again shown to select an option from. If the user selects the first game, "Guess the Number", the program will randomly generate a number between 10 and 30 (inclusive) and allow the user at most 10 (ten) chances to guess it. If the user can correctly guess the number within 10 chances, she/he is awarded one point, otherwise zero point is awarded. After a round is over, the user is asked if she/he wants to play a game again or not. If the user enters a Y', she/he is again shown the list of games to choose from. If the user anything else, she/he is shown the total number of points obtained in this session of play (each round contributes at most one point) and the program exits. Implementation: You need to implement the program using 5 (five) functions: (i) (ii) (iii) (iv) (v) get_validated_input get_game_choice play_math_challenge_game play_guess_the_number_game main Each of these functions is dedicated to performing a single task. (i) gets a number from the user within a specified range, (ii) gets a number from the user indicating which game she/he wants to play, (iii) shows a message that this game is not currently playable, (iv) implements the game 'Guess the Number', and (v) is the function that drives the program by presenting the user game options, collecting the option and calling the appropriate game function, asking the choice to continue playing, showing the total points at the end, bidding goodbye, etc. Sample Outputs: Sample output #1 Available games: 1. Guess the number 2. Math challenge Please enter your choice (1/2): 1 =============== Guess the number =============== I am thinking a number between 10 and 30 You have 10 chances left to guess the number Please enter your guess (10-30): 2 Please enter your guess (10-30): 22 Sorry, you guessed wrong. Try again. You have 9 chances left to guess the number Please enter your guess (10-30): 24 Sorry, you guessed wrong. Try again. You have 8 chances left to guess the number Please enter your guess (10-30): 11 Sorry, you guessed wrong. Try again. You have 7 chances left to guess the number Please enter your guess (10-30): 12 Sorry, you guessed wrong. Try again. You have 6 chances left to guess the number Please enter your guess (10-30): 15 Sorry, you guessed wrong. Try again. You have 5 chances left to guess the number Please enter your guess (10-30): 18 Correct guess! Enter 'Y' if you want to continue. n You are leaving with 1 points ************* 318 ************

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 5GZ
icon
Related questions
Question

I need this done in python. I have provided the code my professor gave my class, and am required to complete steps 4 and 5, as 1, 2, 3 are done for me. Thanks.

 

import random

def get_validated_input(lo, hi, prompt):
user_input = int(input(prompt))

while not lo <= user_input <=hi:
user_input = int(input(prompt))

return user_input

def get_game_choice():
print()
print('Available games:')
print('1. Guess the number')
print('2. Math challenge')
print()
input_prompt = 'Please enter your choice (1/2):'

choice = get_validated_input(1,2,input_prompt)

return choice

def play_math_challenge_game():
print('We are having technical difficulties with this game. Please check back again later.')
print()

def play_guess_the_number_game():
pass # delete this pass statement (needed for an empty function in the skeleton)

def main():
pass # delete this pass statement (needed for an empty function in the skeleton)

main()

Problem Description:
In this assignment, you will need to write a program that will allow the user to play a game. The
program will start with showing the user a list of two games ('Guess the Number' and 'Math
Challenge') and ask the user which one she/he wants to play. However, to keep the assignment
manageable, you are being asked to implement only the first of these two games. If the user selects
the second game, a 'technical error' message is shown, and the list of games is again shown to
select
an
option from.
If the user selects the first game, "Guess the Number", the program will randomly generate a
number between 10 and 30 (inclusive) and allow the user at most 10 (ten) chances to guess it. If
the user can correctly guess the number within 10 chances, she/he is awarded one point, otherwise
zero point is awarded. After a round is over, the user is asked if she/he wants to play a game again
or not. If the user enters a Y', she/he is again shown the list of games to choose from. If the user
anything else, she/he is shown the total number of points obtained in this session of play (each
round contributes at most one point) and the program exits.
Implementation:
You need to implement the program using 5 (five) functions:
(i)
(ii)
(iii)
(iv)
(v)
get_validated_input
get_game_choice
play_math_challenge_game
play_guess_the_number_game
main
Each of these functions is dedicated to performing a single task. (i) gets a number from the user
within a specified range, (ii) gets a number from the user indicating which game she/he wants to
play, (iii) shows a message that this game is not currently playable, (iv) implements the game 'Guess
the Number', and (v) is the function that drives the program by presenting the user game options,
collecting the option and calling the appropriate game function, asking the choice to continue
playing, showing the total points at the end, bidding goodbye, etc.
Sample Outputs:
Sample output #1
Available games:
1. Guess the number
2. Math challenge
Please enter your choice (1/2): 1
===============
Guess the number
===============
I am thinking a number between 10 and 30
You have 10 chances left to guess the number
Please enter your guess (10-30): 2
Please enter your guess (10-30): 22
Sorry, you guessed wrong. Try again.
You have 9 chances left to guess the number
Please enter your guess (10-30): 24
Sorry, you guessed wrong. Try again.
You have 8 chances left to guess the number
Please enter your guess (10-30): 11
Sorry, you guessed wrong. Try again.
You have 7 chances left to guess the number
Please enter your guess (10-30): 12
Sorry, you guessed wrong. Try again.
You have 6 chances left to guess the number
Please enter your guess (10-30): 15
Sorry, you guessed wrong. Try again.
You have 5 chances left to guess the number
Please enter your guess (10-30): 18
Correct guess!
Enter 'Y' if you want to continue. n
You are leaving with 1 points
************* 318 ************
Transcribed Image Text:Problem Description: In this assignment, you will need to write a program that will allow the user to play a game. The program will start with showing the user a list of two games ('Guess the Number' and 'Math Challenge') and ask the user which one she/he wants to play. However, to keep the assignment manageable, you are being asked to implement only the first of these two games. If the user selects the second game, a 'technical error' message is shown, and the list of games is again shown to select an option from. If the user selects the first game, "Guess the Number", the program will randomly generate a number between 10 and 30 (inclusive) and allow the user at most 10 (ten) chances to guess it. If the user can correctly guess the number within 10 chances, she/he is awarded one point, otherwise zero point is awarded. After a round is over, the user is asked if she/he wants to play a game again or not. If the user enters a Y', she/he is again shown the list of games to choose from. If the user anything else, she/he is shown the total number of points obtained in this session of play (each round contributes at most one point) and the program exits. Implementation: You need to implement the program using 5 (five) functions: (i) (ii) (iii) (iv) (v) get_validated_input get_game_choice play_math_challenge_game play_guess_the_number_game main Each of these functions is dedicated to performing a single task. (i) gets a number from the user within a specified range, (ii) gets a number from the user indicating which game she/he wants to play, (iii) shows a message that this game is not currently playable, (iv) implements the game 'Guess the Number', and (v) is the function that drives the program by presenting the user game options, collecting the option and calling the appropriate game function, asking the choice to continue playing, showing the total points at the end, bidding goodbye, etc. Sample Outputs: Sample output #1 Available games: 1. Guess the number 2. Math challenge Please enter your choice (1/2): 1 =============== Guess the number =============== I am thinking a number between 10 and 30 You have 10 chances left to guess the number Please enter your guess (10-30): 2 Please enter your guess (10-30): 22 Sorry, you guessed wrong. Try again. You have 9 chances left to guess the number Please enter your guess (10-30): 24 Sorry, you guessed wrong. Try again. You have 8 chances left to guess the number Please enter your guess (10-30): 11 Sorry, you guessed wrong. Try again. You have 7 chances left to guess the number Please enter your guess (10-30): 12 Sorry, you guessed wrong. Try again. You have 6 chances left to guess the number Please enter your guess (10-30): 15 Sorry, you guessed wrong. Try again. You have 5 chances left to guess the number Please enter your guess (10-30): 18 Correct guess! Enter 'Y' if you want to continue. n You are leaving with 1 points ************* 318 ************
1 import random
2
3 def get_validated_input(lo, hi, prompt):
user_input = int(input(prompt))
4
6
while not lo <= user input <=hi:
user_input = int (input (prompt))
%3D
8
9
return user_input
10
11 def get_game_choice():
print()
print('Available games:')
print('1. Guess the number')
print('2. Math challenge')
print()
input_prompt = 'Please enter your choice (1/2):'
12
13
14
15
16
17
18
19
choice = get_validated_input (1,2, input_prompt)
%3D
20
21
return choice
22
def play_math_challenge_game ():
print('We are having technical difficulties with this game. Please check back again later.')
print()
23
24
25
26
27 def play_guess_the_number_game ():
# delete this pass statement (needed for an empty function in the skeleton)
28
pass
29
30 def main():
31
pass
# delete this pass statement (needed for an empty function in the skeleton)
32
33 main()
34
Transcribed Image Text:1 import random 2 3 def get_validated_input(lo, hi, prompt): user_input = int(input(prompt)) 4 6 while not lo <= user input <=hi: user_input = int (input (prompt)) %3D 8 9 return user_input 10 11 def get_game_choice(): print() print('Available games:') print('1. Guess the number') print('2. Math challenge') print() input_prompt = 'Please enter your choice (1/2):' 12 13 14 15 16 17 18 19 choice = get_validated_input (1,2, input_prompt) %3D 20 21 return choice 22 def play_math_challenge_game (): print('We are having technical difficulties with this game. Please check back again later.') print() 23 24 25 26 27 def play_guess_the_number_game (): # delete this pass statement (needed for an empty function in the skeleton) 28 pass 29 30 def main(): 31 pass # delete this pass statement (needed for an empty function in the skeleton) 32 33 main() 34
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,