안녕하세요, 저는 이미 두 번 질문하지만 저는 답을 찾을 수 없다는 것을 알고 있습니다. 질문은 내 번호 게임의 역 추측에 관한 것입니다. 코드는 프로그램을 실행하지만 "인간과 같은"방식으로 실행하지는 않습니다. 숫자가 50이고 20이 더 높다고 추측하면 컴퓨터는 예를 들어 30이라고 말합니다. 응답이 낮을 것으로 추측합니다. 15. 어떻게 해결합니까? 연습은 다음과 같습니다. 절대 초보자를위한 Python. 누군가 나를 도울 수 있습니까? 나는 책에서 건너 뛴다. 코드를 보면 내가 아는 것과 볼 수없는 것을 볼 수 있다고 생각합니다. Binary Search에 최대 읽기역방향 게임 파이썬
#Guess My Number
#
#The computer picks a random number between 1 and 100
#The playes tries to guess it and the coputer lets
#the player know if the guess is too high, too low
#or right on the money
print ("\t// // // // // // // // // //")
print ("\tWelcome to 'Guess My Number'!")
print ("\tComputer VS Human")
print ("\t// // // // // // // // // //")
name = input("What's your name?")
print ("Hello,", name)
print ("\nOkay, think of a number between 1 and 100.")
print ("I'll try to guess it within 10 attemps.")
import random
#set the initial values
the_number = int(input("Please type in the number to guess:"))
tries = 0
max_tries = 10
guess = random.randint(1, 100)
#guessing loop
while guess != the_number and tries < max_tries:
print("Is it", guess,"?")
tries += 1
if guess > the_number and tries < max_tries:
print ("It's lower")
guess = random.randint(1, guess)
elif guess < the_number and tries < max_tries:
print ("It's higher")
guess = random.randint(guess, 100)
elif guess == the_number and tries < max_tries:
print("Woohoo, you guessed it!")
break
else:
print("HAHA you silly computer it was", the_number,"!")
input ("\n\nTo exit, press enter key.")
고맙습니다.하지만 코드에 어디에 넣어야합니까? – bogaardesquat
'import random '뒤에'lowest'와'highest' 두 개의 변수를 선언하십시오. "lower"와 "higher"if 문 모두에서 변수의 값을 재조정합니다. 여러분이 추측 할 때마다'guess = random.randint (최저, 최고)' – Lanaru