Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python question Question 1 Write a Python program to play two games. The program should be menu driven and should use different functions to play
python question
Question 1 Write a Python program to play two games. The program should be menu driven and should use different functions to play each game. Call the file containing your program fun_games.py. Your program should include the following functions: function guessTheNumber which implements the number guessing game. This game is played against the computer and outputs the result of the game (win/lose) as well as number of guesses the user made to during the game, and the correct answer if the user doesn't guess it. In addition, for the benefit of the human player, the function should also display some information as to how the game will be played. To play the game, the computer selects a random number between 1 and 50, inclusive, and asks the user to guess the number. The user gets 5 chances to guess the number and along the way the program should tell the user if they are guessing too high or too low. Sample input/output for this game, where the user wins, is: Let us play Guess the Number! I am thinking of a number between 1 and 50 (inclusive) Try to guess the number and I will give you hints along the way. You have at most 5 tries to guess the number. Enter a number between 1 and 50: 30 Too low! Guess a number higher than 30 Enter a number between 1 and 50: 40 Too low! Guess a number higher than 40 Enter a number between 1 and 50: 45 Too low! Guess a number higher than 45 Enter a number between 1 and 50: 48 Congratulations!!! You win in 4 tries. Sample input/output for this game, where the user loses, is: Let us play Guess the Number! I am thinking of a number between 1 and 50 (inclusive) Try to guess the number and I will give you hints along the way. You have at most 5 tries to guess the number. Enter a number between 1 and 50: 30 Too low! Guess a number higher than 30 Enter a number between 1 and 50: 50 Too high! Guess a number lower than 50 Enter a number between 1 and 50: 40 Too low! Guess a number higher than 40 Enter a number between 1 and 50: 45 Too low! Guess a number higher than 45 Enter a number between 1 and 50: 48 Too high! Guess a number lower than 48 Game over. You used up all 5 tries. The number was 46 - better luck next time! function aimForTarget which implements the aim for the target game. This game is played with two players. The target simulated for this game has four concentric circles identified by a range of numbers and each circle is worth a given number of points as follows: Circle 2 Number Range 1-50 51 - 100 101 - 150 151 - 200 Points 100 50 65 75 151 - 200 101 - 150 1 - 100 50 Circle 2:50 points Circle 1: 100 points Circle 3: 65 points Circle 4: 75 points To play the game, each player enters her/his name and a number from 1 to 200. The computer (i.e., your program) chooses, randomly, a number from 1 4 representing the circle number which it thinks identifies the range where your number will land. If the computer is correct, then you get all of the points for that circle. If the computer is incorrect, then your score will be calculated as follows: If your given number is above the computer's chosen circle's range, then you get half the difference of your given number and the computer's chosen circle's upper range as your number of points. If your given number is below the computer's chosen circle's range, then you get half the number of points for the computer's chosen circle. The computer chooses a different random circle for each player. The player with the highest score wins and this player's name should be displayed as the winner. Ties should also be reported. To calculate each player's points, include a function called getPoints which takes the user's chosen number as well as the randomly selected circle number, and returns the points awarded. The header for this function would look like: def getPoints (userNum, rndCircleNum): Sample input/output for this game, where the Player 1 wins, is: Player 1 enter your first name: Bob Bob please enter a number between 1 and 200 (inclusive: 60 Player 2 enter your first name: Sue Sue please enter a number between 1 and 200 (inclusive: 30 Points for Bob are 37.5 Random circle for Player 1 was: 4 Points for Sue are 25.0 Random circle for Player 2 was: 2 Bob wins! Sample input/output for this game, where the Player 2 wins, is: Player 1 enter your first name: Joe Joe please enter a number between 1 and 200 (inclusive): 150 Player 2 enter your first name: Mary Mary please enter a number between 1 and 200 (inclusive): 180 Points for Joe are 65 Random circle for Player 1 was: 3 Points for Mary are 75 Random circle for Player 2 was: 4 Mary wins! Sample input/output for this game, where there is a tie, is: Player 1 enter your first name: Jane Jane please enter a number between 1 and 200 (inclusive): 150 Player 2 enter your first name: Tom Tom please enter a number between 1 and 200 (inclusive): 50 Points for Jane are 37.5 Random circle for Player 1 was: 4 Points for Tom are 37.5 Random circle for Player 2 was: 4 It is a tie! function displayMenu which displays the menu (given below), allows the user to choose a game to be played and returns the number associated with the game selected by the user. Choose one of the following games to play 1. Guess the Number 2. Aim for the Target Enter your choice of game as 1 or 2: function main that repeatedly uses the function displayMenu until the user decides to stop playing the games Sample input/output for the whole game is: Choose one of the following games to play 1. Guess the Number 2. Aim for the Target Enter your choice of game as 1 or 2: 1 Let us play Guess the Number! I am thinking of a number between 1 and 50 (inclusive) Try to guess the number and I will give you hints along the way. You have at most 5 tries to guess the number. Enter a number between 1 and 50: 30 Congratulations!!! You win in 1 tries. function main that repeatedly uses the function displayMenu until the user decides to stop playing the games Sample input/output for the whole game is: Choose one of the following games to play 1. Guess the Number 2. Aim for the Target Enter your choice of game as 1 or 2: 1 Let us play Guess the Number! I am thinking of a number between 1 and 50 (inclusive) Try to guess the number and I will give you hints along the way. You have at most 5 tries to guess the number. Enter a number between 1 and 50: 30 Congratulations!!! You win in 1 tries. Do you wish to play again? Enter y or n: y Choose one of the following games to play 1. Guess the Number 2. Aim for the Target Enter your choice of game as 1 or 2: 2 Player 1 enter your first name: Bill Bill please enter a number between 1 and 200 (inclusive): 180 Player 2 enter your first name: Jill Jill please enter a number between 1 and 200 (inclusive): 75 Points for Bill are 75 Random circle for Player 1 was: 4 Points for Jill are 12.5 Random circle for Player 2 was: 1 Bill wins! Do you wish to play again? Enter y or n: n Goodbye. Hope you enjoyed playingStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started