Code a guessing game in Python Parameters: The number guessing game allows the user to enter a guess for a number that the computer generates between 1 and 10. The user can make only one guess per game. If the guess is incorrect, the game ends. If a guess is correct the user wins. Either way the user may play again. Each time the user wins. they collect 5 points. To implement this game, write code for the following: GenerateGuess() which is a function that generates a random guess. I will give you the code for this function. But at the very top of the code page you must type: from random import randint  #this is python code so follow the case properly and this is the top line with no indentation

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Code a guessing game in Python

Parameters:

  • The number guessing game allows the user to enter a guess for a number that the computer generates between 1 and 10.
  • The user can make only one guess per game. If the guess is incorrect, the game ends. If a guess is correct the user wins. Either way the user may play again.
  • Each time the user wins. they collect 5 points.

To implement this game, write code for the following:

  • GenerateGuess() which is a function that generates a random guess. I will give you the code for this function. But at the very top of the code page you must type:
    • from random import randint  #this is python code so follow the case properly and this is the top line with no indentation

#then here is that GenerateGuess
def GenerateGuess():
      return (randint(1, 10))

Write another function that takes a user's guess and the current 'secret' guess and if the user's guess is correct , add the points to their score and return True, otherwise return False.
Call this CheckGuess

Now you write code for main:

def main():
      print("Let's play the number Guessing Game")      
             UserGuess = int(input("Make a guess: "))
             ComputerGuess = #Call the GenerateGuess to return a value in this ComputerGuess variable
             if   CheckGuess(........,.......)                            #Pass CheckGuess the computerGuess and the UserGuess. It will return True or False

                  #If CheckGuess returns True, add 5 points to the user TotalPoints. This variable must be global. 
                  #otherwise display you lost msg.
            #Ask if the user wants to play again. If yes, call main. 
                   # If user does not want to play again, don't call main. the code will end. Just display a good bye msg with the TotalPoints won.
                                            

Note when you call main from main, it gives the user the appearance that the game is repeating. 

You need to write the CheckGuess function to return True if the user's guess parameter is the same as the computer's guess parameter. Otherwise this function returns False.

You also need the TotalPoints variable to be initialized at 0 at the top. Then use the global keyword each time you want to use that variable in any other function. This way this variable will retain its content.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Files and Directory
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education