correct_guess = input("Is the number 50? (yes/no)") print(correct_guess)
bottom = 1 top = 100 correct_guess = "no" while correct_guess != "yes": correct_guess = input("Is the number "+str((top+bottom)//2)+"? (yes/no)")
$ python hw_guess.py Is the number 50? (yes/no)no Is the number 50? (yes/no)no Is the number 50? (yes/no)yes
bottom = 1 top = 100 correct_guess = "no" while correct_guess != "yes": guess = (top+bottom)//2 correct_guess = input("Is the number "+str(guess)+"? (yes/no)") if correct_guess == "no": higher = input("Is the number higher than "+str(guess)+"? (yes/no)")
$ python hw_guess.py Is the number 50? (yes/no)no Is the number higher than 50? (yes/no)yes Is the number 50? (yes/no)yes
bottom = 1 top = 100 correct_guess = "no" while correct_guess != "yes": guess = (top+bottom)//2 correct_guess = input("Is the number "+str(guess)+"? (yes/no)") if correct_guess == "no": higher = input("Is the number higher than "+str(guess)+"? (yes/no)") if higher == "yes": bottom = guess else: top = guess
$ python hw_guess.py Is the number 50? (yes/no)no Is the number higher than 50? (yes/no)no Is the number 25? (yes/no)no Is the number higher than 25? (yes/no)yes Is the number 37? (yes/no)no Is the number higher than 37? (yes/no)no Is the number 31? (yes/no)no Is the number higher than 31? (yes/no)yes Is the number 34? (yes/no)no Is the number higher than 34? (yes/no)yes Is the number 35? (yes/no)yes
bottom = 1 top = 100 correct_guess = "no" number_of_guesses = 0 while correct_guess != "yes": number_of_guesses += 1 guess = (top+bottom)//2 correct_guess = input("Is the number "+str(guess)+"? (yes/no)") if correct_guess == "no": higher = input("Is the number higher than "+str(guess)+"? (yes/no)") if higher == "yes": bottom = guess else: top = guess else: print("Yeey, I got it in "+ str(number_of_guesses)+" tries")
$ python hw_guess.py Is the number 50? (yes/no)no Is the number higher than 50? (yes/no)yes Is the number 75? (yes/no)no Is the number higher than 75? (yes/no)no Is the number 62? (yes/no)no Is the number higher than 62? (yes/no)yes Is the number 68? (yes/no)yes Yeey, I got it in 4 tries
bottom = 1 top = 100 correct_guess = "no" number_of_guesses = 0 play_again = "yes" while play_again == "yes": while correct_guess != "yes": number_of_guesses += 1 guess = (top+bottom)//2 correct_guess = input("Is the number "+str(guess)+"? (yes/no)") if correct_guess == "no": higher = input("Is the number higher than "+str(guess)+"? (yes/no)") if higher == "yes": bottom = guess else: top = guess else: print("Yeey, I got it in "+ str(number_of_guesses)+" tries") play_again = input("Would you like to play again? (yes/no)") correct_guess = "no"
$ python hw_guess.py Is the number 50? (yes/no)yes Yeey, I got it in 1 tries Would you like to play again? (yes/no)yes Is the number 50? (yes/no)no Is the number higher than 50? (yes/no)yes Is the number 75? (yes/no)yes Yeey, I got it in 3 tries Would you like to play again? (yes/no)no