'내 번호 추측'게임에 대한 Python 3 코드를 작성하고 있습니다. 그러나이 버전에서 컴퓨터는 사용자가 비밀로 유지 한 숫자를 추측해야합니다. 저는 파이썬과 프로그래밍에 익숙하지 않으며 약간의 도움에 감사 할 것입니다. 유형 변환과 관련된 오류가 발생합니다. 여기에 오류가 :'내 번호 추측'게임에서 유형 변환 오류가 발생했습니다.
Traceback (most recent call last):
File "C:\Users\Documents\python\GuessMyNumberComputer.py", line 16, in <module>
response = input("Is the number" +guess +"? \n Press (y - yes, l - go lower, h - go higher)")
**TypeError: Can't convert 'int' object to str implicitly**
는 그리고 여기 내 코드입니다 :
이import random
print("\t\t\t Guess My Number")
input("Think of a number between 1 and 100 and I will try to guess it. \nPress enter when you have thought of your number and are ready to begin.")
a = 1
b = 100
tries = 0
while 1==1:
guess = random.randint(a,b)
response = input("Is the number" +guess +"? \n Press (y - yes, l - go lower, h - go higher)")
tries += 1
if response == y:
break
elif response == l:
b = response-1
elif response == h:
a = response+1
print("Aha! I guessed it! And it only took",tries,"tries!")
input("Press enter to exit.")
누군가가이 오류와 함께 나를 도울 수는? 내 책이이 영역을 다루지 않는 것 같아서이 부분을 읽을 수 있도록 웹의 일부 링크를 가르쳐 주시겠습니까?
감사합니다.
사용'동안 TRUE '대신'1 == 1 '동안. – ApproachingDarknessFish