Python Forum

Full Version: When I run this code, nothing happens. Could someone please tell me why?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)
         
You define the function but you don't call it.
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.
If you want to keep the result, assign it to a name.

result = guess(3, 7)
(Oct-21-2020, 03:48 PM)DeaD_EyE Wrote: [ -> ]If you want to keep the result, assign it to a name.

result = guess(3, 7)

Oops, that's right from the returned value.