简体   繁体   中英

In python 3.2, how to compare a symbols e.g. >

Im writing a function which will guess what number I'm thinking of, but how do I compare a symbol like a > or less than symbol?

def NumberGuess (low,high):
    guess = ((low+high//2)

    if str(input(guess,"?")) == (">") :
         NumberGuess (guess,high)
    elif str(input(guess,"?")) == "<":
         NumberGuess (low,guess)
    else:
         str(input(guess,"?")) == "="

This is what I have so far, I could do it another way but this is bugging me now and I wanna figure it out Any help is appreciated!

def NumberGuess (lo,hi):
    guess = (lo+hi)//2
    user_guess = input("Please, input '>' or '<' as a guess: ")
    if user_guess == ">" :
        ReverseNumberGuess (guess,hi)
    elif user_guess == "<":
        ReverseNumberGuess (lo,guess)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM