-1

Here is my code:

import random
def guessGame(x):
    low=1
    high=x
    feedback=" "

    while feedback != "c":
        if high!=low:
            guess=int(random.randint(low,high))
        else:
            guess=low

        feedback= input(f"Is it {guess} too high(H),too lowe(L) or correct(C)?").lower()
        if feedback == "h":
            high = guess-1
        elif feedback == "l":
            low=guess+1
    print(f"I guess the correct number{guess}!")

x=input("Please input a highest number in the range: ")
guessGame(x)

I wrote a python code to ask my computer to guess a secret number. But it did not work. I did some changes but still do know where I did wrong.

  • `x` is a string, so I expect your `randint` call is failing with a `TypeError` due to `high` also being a string. Do `x = int(input("Please input a highest number in the range: "))` to make it an int instead. – Samwise Feb 12 '22 at 08:13
  • 1
    *"it does not work"* is not a proper problem description. – gre_gor Feb 12 '22 at 08:16
  • Please include the _actual_ error that you are getting. – Gino Mempin Feb 12 '22 at 08:19
  • @Samwise thank you so much. It is very helpful. sorry for the non proper description since it is my first time asking question. I will ask better next time. thank you. – HarperEsc Feb 13 '22 at 13:20

1 Answers1

0

Python input type is a string you must convert to string to integer

x=int(input("Please input a highest number in the range: "))
Anil_Can
  • 3
  • 2