私は以下のPythonコードを書いています.1〜100の数字を推測することになっています。考えている数値が高いか低いかを教えてください。私はそれを再生しようとしたとき、私は私の電話番号は、それが低いか、またはその逆だということを言った後に高いことを伝えるときしかし、いくつかの理由で、それは常に立ち往生:なぜこの推測コードがPythonで停止しているのですか
import random
import time
import math
correct = 0
goon = 'yes'
biggest = 100
smallest = 1
tries = 10
print 'Hi!'
time.sleep(0.5)
print 'I´m going to try and guess your number'
time.sleep(0.5)
print 'Just tell me if your number is bigger or smaller than what I guessed'
time.sleep(0.5)
print 'And of course you have to tell me when I´m right, ok?'
time.sleep(0.5)
print 'Type "b" if your number is smaller than what I guessed and type "s" if it´s bigger. When I´m right, type "r".'
time.sleep(0.5)
print 'Oh by the way, your number should be between 1 and 100.'
if goon == 'no' or goon == 'No' or goon == 'n':
print 'Ok, see you soon!'
else:
while goon == 'yes' or goon == 'Yes' or goon == 'y':
guess = random.randint(1,100)
print guess
answer = raw_input()
while correct == 0:
if answer == 'r':
correct = 1
endhooray = random.randint(1, 3)
if endhooray == 1:
print 'Yay, I got it!'
elif endhooray == 2:
print 'Finally!'
elif endhooray == 3:
print 'See, I´m good at this!'
elif answer == 'b':
smallest = guess
difference = 100 - guess
add = random.randint(1, difference)
guess = guess + add
if guess < biggest:
print guess
answer = raw_input()
elif guess > biggest:
while tries == 10:
add = random.randint(1, difference)
guess = guess + add
if guess < biggest:
print guess
answer = raw_input()
tries == 1000000
elif answer == 's':
biggest = guess
difference = guess - 100
difference = difference * -1
subtract = random.randint(1, difference)
guess = guess - subtract
if guess > smallest:
print guess
answer = raw_input()
elif guess < smallest:
while tries == 10:
subtract = random.randint(1, difference)
guess = guess - subtract
if guess > smallest:
print guess
answer = raw_input()
tries = 100000
else:
print 'Oops, I don´t know what that means'
break
問題を引き起こしたのと同じ入力を使用して、Pythonインタープリタであるかのように、コードを紙面で実行することをお勧めします。あなたは間もなく間違ったことをすぐに理解するでしょう – user234461
私はこれまで数回これを行ってきましたが、なぜそれがうまくいかないのかの理由を見つけることはできません。 – shayan012
教えてください:/ – shayan012