我应该在我的"猜一个数字"程序?

时间:2018-02-23 15:42:17

标签: python-3.x exception

我的任务中的一个练习是制作猜测数字的程序:

min=1
max=10
count=1

answer=input("Think of af number between "+str(min)+" and "+str(max)+" and then press enter ")

while answer!="correct":

    if min>max:
        print("\nYou are cheating! Good bye.")
        break

    else:
        guess=(min+max)//2
        answer=input("My no."+str(count)+" guess is "+str(guess)+" - enter 'higher', 'lower' or 'correct': ")

        if answer=="correct":
            print("I guessed it!")

        elif answer=="higher":
            min=guess+1
            count+=1

        elif answer=="lower":
            max=guess-1
            count+=1

        else:
            print("\nCouldn't recognize your input, please try again.")

我们刚刚接受了关于异常的教导,但我不确定在这种情况下使用异常是否有意义,可能代替else语句?

0 个答案:

没有答案