ポイントは、整数の間隔から選択された乱数を推測し、一定の試行回数内でそれを行うことです。
このmain
関数は、間隔の上限と、ユーザーが与えることができる推測の数を尋ねます。次に、コア関数は推測された値を返す必要があるため、数値が正しい場合、関数はすぐに終了する必要があります。
デバッグ中にいくつかのprintステートメントを入れましたが、関数からステートメントy
に値が返されないことがわかりました。while
core
# -*- coding: utf-8 -*-
def main():
from random import choice
p = input("choose upper limit: ")
t = input("how many attempts: ")
pool = range(p+1)
x = choice(pool)
i = 1
while ((x != y) and (i < t)):
core(x,y)
i += 1
def core(x,y):
y = input("choose a number: ")
if y == x:
print("You gussed the right number!")
return y
elif y > x:
print("The number is lower, try again")
return y
else:
print("The number is higher, try again")
return y