Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

number guessing game python

from random import randint
from pcinput import getInteger

answer = randint(1, 200)
count = 0

while True:
    guess = getInteger("What is your estimate? ")
    if guess < 1 or guess > 200:
        print("Your estimate must be between 1 and 200")
        continue
    count += 1
    if guess < answer:
        print("Higher")
    elif guess > answer:
        print("lower")
    else:
        print("You guessed it!")
        break

if count == 1:
    print("Wow first try !!.")
else:
    print("You estimated it in", count, "times.")
 
PREVIOUS NEXT
Tagged: #number #guessing #game #python
ADD COMMENT
Topic
Name
1+6 =