samedi 8 février 2020

Input not mapping with the elif clause

I am new to learning python and programming in general. I wrote this code for computer to guess a number that i imagined (in between 1 to 100). It is showing me the same output "Sorry, I did not understand your input." which is applicable only if my input doesnot match l, h or c. In cases where my input is l,h or c, it should take those conditions and follow up to finally reach to an outcome. But that isn't happening.I am trying to use bisection method. Can you please help me where is it going wrong ?

num_begin = 0;
num_end = 100;
avg=(num_begin+num_end)/2

print("Please think of a number between 0 and 100!")

print("is your secret number "+ str(avg))
command=input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly")
while (True):
    if (command != 'c' or command != 'h' or command != 'l'):
        print("Sorry, I did not understand your input.")
        print("is your secret number "+ str(avg))
        command=input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly")

    elif(command=='l'):
        num_begin=avg
        avg=(num_begin+num_end)/2
        print("is your secret number "+ str(avg))
        command=input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly")

    elif(command=='h'):
        num_end=avg
        avg=(num_begin+num_end)/2
        print("is your secret number "+ str(avg))
        command=input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly")

    else:
        print("Game over. Your secret number was: " + str(avg))
        break

Aucun commentaire:

Enregistrer un commentaire