Python Forum
When I run this code, nothing happens. Could someone please tell me why?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
When I run this code, nothing happens. Could someone please tell me why?
#1
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)
         
Reply
#2
You define the function but you don't call it.
Reply
#3
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.
Reply
#4
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!
Reply
#5
(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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020