Python Forum
making a guessing number game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
making a guessing number game
#1
Hi for my intro AI school project I had to make a number guessing game. Is there a way to somehow put this in like some graphics. I'm pretty new to this, but I do understand the basics fairly well now. I just want to put it like in an application window with actual graphics, so that it looks nicer.
Here's my code:

# programme generates a random number
# user needs to guess number input
# if wrong indication of how wrong too high or too low
# if guess correct positive indication
# function to check if input is actual number
# function to see difference between input and r number
# compare numbers
# add a score if one gets the answer right.
# programme generates a random number

import random

# global variable
score = 0
game_run = True

def start_game():
    global score
    global game_run
    guess = int(input("Guess a number between 1 and 20: "))
    rnum = random.randint(1, 20)
    while guess != rnum:
        if guess > rnum:
            print("Your number is too high")
            guess = int(input("Guess a number between 1 and 20: "))
        elif guess < rnum:
            print("Your number is too low") 
            guess = int(input("Guess a number between 1 and 20: "))       
    if guess == rnum:
        score += 1
        print("You got it correct!")
        contin = input("Do you want to continue? \n Yes \n No \n")
        if contin == "Yes" or contin == "yes":
            game_run = True
        else:
            game_run = False    
while game_run:
    start_game()
    if game_run == False:
        print("Your score is: {}".format(score))
Reply
#2
There are several ways to do this in Python, but probably the most common way is by using the tkinter module. You can find documentation for it here.

If you want to see some code that uses tkinter, you'll find several examples in the Code Sharing and Code Review forums. As you learn how to use tkinter, you may want to ask any questions you have in the GUI forum.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Play again, in a guessing game banidjamali 4 11,689 Jan-22-2021, 06:23 AM
Last Post: banidjamali
  Help - random number/letter guessing game juin22 1 3,194 Aug-16-2020, 06:36 AM
Last Post: DPaul
  Dynamically chosing number of players in a "game" nsadams87xx 5 4,157 Jul-17-2020, 02:00 PM
Last Post: deanhystad
  Can someone help me optimize this game for large number of strings Emekadavid 13 4,939 Jul-06-2020, 06:16 PM
Last Post: deanhystad
  Guessing game with 4 different digits LinseyLogi 6 3,637 Mar-29-2020, 10:49 AM
Last Post: pyzyx3qwerty
  Guess the number game jackthechampion 5 3,178 Mar-07-2020, 02:58 AM
Last Post: AKNL
  Asking for help in my code for a "Guess the number" game. Domz 5 3,813 Aug-14-2019, 12:35 PM
Last Post: perfringo
  Guessing game with comparison operators Drone4four 9 13,771 Dec-02-2018, 06:12 PM
Last Post: ichabod801
  Guess a number game Drone4four 4 5,260 Nov-16-2018, 03:56 AM
Last Post: Drone4four
  Guessing Game "limit 4 attempts" help rprollin 3 19,731 Jun-23-2018, 04:37 PM
Last Post: ljmetzger

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020