November 28, 2019

To guess number between 0 zero and 100 hundred in python


To guess number between 0 zero and 100 hundred in python


if __name__=='__main__':
    isnum=False
    num=100
    upprnge=100
    lwrnge=0
    lst=[]
    print('Think of number between 0 and 100..')
    while not isnum:
        print(num, upprnge,lwrnge)
        isnum1 = input("Is "+str(num)+" the number?y/n ")
        if isnum1=='y':
            isnum=True
        elif isnum1=='n':
            isnum2 = input("Is "+str(num)+" high?y/n ")
            if isnum2=='y':
                if upprnge >= num:
                    upprnge=num
                    num = lwrnge + round((upprnge-lwrnge)/2,0)
            elif isnum2=='n':
                if lwrnge <= num:
                    lwrnge=num
                num = upprnge - round((upprnge-lwrnge)/2,0)
            lst.append(num)
            print(lst)
    print('number is ', num)


Developed in python by steffi

No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments