Oct-20-2020, 03:52 PM
def guess(x, y): a = (x+y)//2 print(a) d = input("Please type high, low, or correct:") if d == ("correct"): print("I guessed your number!") elif d == "high": return guess(x, a-1) elif d == "low": return (a+1,y)
When I run this code, nothing happens. Could someone please tell me why?
|
Oct-20-2020, 03:52 PM
def guess(x, y): a = (x+y)//2 print(a) d = input("Please type high, low, or correct:") if d == ("correct"): print("I guessed your number!") elif d == "high": return guess(x, a-1) elif d == "low": return (a+1,y)
Oct-20-2020, 03:54 PM
You define the function but you don't call it.
Oct-21-2020, 01:45 PM
def guess(x, y): a = (x+y)//2 print(a) d = input("Please type high, low, or correct:") if d == ("correct"): print("I guessed your number!") elif d == "high": return guess(x, a-1) elif d == "low": return (a+1,y) guess(3, 7) #<-- put numbers whatever you wants.
Oct-21-2020, 03:48 PM
If you want to keep the result, assign it to a name.
result = guess(3, 7)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Oct-23-2020, 09:40 AM
|
|