Jul-01-2020, 09:30 PM
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:
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))
