loading
open in
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#Programmer Name: Eric Evans, M.Ed.
#Program Name: Number Guesser (Hi/Lo Random)
#Program Description: Uses a Hi/Lo Random algorithm to determine the number chosen the user.
#Algorithm: Starts with hi/lo or 100/1. Selects a random number between hi/lo. Adjusts hi/lo accordingly after guess. Repeat selection of a random number between new hi/lo. Repeat hi/lo adjustment...
#
import random
correct = "N"
high = 100
low = 1
guessCount = 1
guess = random.randint(low, high)
while (correct == "N"):
  guess = int(guess)
  guessAsString = str(guess)
  print ("Is Your Number " + guessAsString + "?")
  response = input("[C]orrect  /  Too [L]ow  /  Too [H]igh")
  if (response == "C"):
    guessCountAsString = str(guessCount)
    print("Yay! I got it in " + guessCountAsString + " guesses!")
    correct = "Y"
  elif (response == "L"):
    print ("Too Low Huh?")
    low = guess + 1
    guess = random.randint(low, high)
    guessCount = guessCount + 1
  elif (response == "H"):
    print ("Too High Huh?")
    high = guess - 1
    guess = random.randint(low, high)
    guessCount = guessCount + 1
print ("Exiting Program")
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux