I'm pretty new to python, just started 2 weeks ago xD, and new to forum too, I tried to search to see if there were any other question that was similar to this but couldn't find one. Therefore, I apologize if there's already another thread with the similar problem.
Anyway, my problem is basically I got the script to kind of work. It will ask me to input a starting number and ending number, but I just can't seem to eliminate the task or rather append to the starting or ending number if the guessed number should go higher or lower.
def guessing(): import random tries = 1 start = int(input("Input starting number")) end = int(input("Input ending number")) init_guess = random.randint(start, end) print(init_guess) answ = input("Is this the right number?") while answ != "yes": right = input("Is it higher or lower?") if right == 'higher': guess = random.randint(init_guess, end) print(guess) guess = init_guess answ = input("Is this the right number?") tries += 1 elif right == 'lower': guess = random.randint(start, init_guess) print(guess) answ = input("Is this the right number?") guess = end_guess tries += 1 else: print("Invalid input, please only use higher or lower as answer") print("I got it right, thank you for playing") return guessing
The thing is I don't think I should be using random.randint, does anyone have any suggestion? I tried to create a variable to append to the guessed number but I keep failing. It kind of work but the result would be if I put higher it would indeed go higher yet if I put lower it would go to a number that was lowered than the already guessed number. X_X Please help and point out if I made any unnecessary line of code, thank you. btw this problem was a challenge by a book I was reading but they didn't put any answer to it.