Guessing algorithm does not seem to work, guessing number by Python

前端 未结 3 1643
长情又很酷
长情又很酷 2021-01-22 00:34

I am struggling with some simple algorithm which should make python guess the given number in as few guesses as possible. It seems to be running but it is extremely slow. What a

3条回答
  •  野性不改
    2021-01-22 01:17

    from random import randint
    
    print('choose a number in your brain and if guess is true enter y else any key choose time of guess: ')
    
    print("define the range (A,B) :")
    A = int(input("A: "))
    B = int(input("B: "))
    time = int(input("time:"))
    
    while time != 0:
        ran = randint(A, B)
        inp = input(f"is this {ran} ?")
        time -= 1
        if inp == "y":
            print("bla bla bla python wins!")
            break
        print("NOPE!")
        if time == 0:
            print("computer game over!")
            break
    

提交回复
热议问题