lundi 9 septembre 2019

Guessing Game Python Infinite Loop

I am trying to teach myself basic python scripting and create the number guessing game, but I am running into an infinite loop for my while loop. The program will infinitely print the first print statement from the initial entry.

#!/usr/bin/python
import random

print("Here is a guessing game!")
print("Try to guess the number. It is a value from 1-100")

answer = random.randint(1,100)
guess = int(input('Enter your guess: '))
counter = 0

while (guess != answer):
   counter += 1
   if guess < answer:
       print('Your guess is too low!')
   elif guess > answer:
       print('Your guess is too high!')
   else:
       print('Correct!')
       print('It took you' + count + ' guesses.')




Aucun commentaire:

Enregistrer un commentaire