Jul-17-2017, 12:43 PM
(This post was last modified: Jul-17-2017, 01:16 PM by sparkz_alot.)
Hi I'm new to the forum and a beginner to python, please take it easy :) I'm trying to do "guess the number" game, but couldn't solve it
The program will generate number from 1 to 99 and I have to input the answer first then input my guess. If my guess(ex:50) it larger than the answer(ex:45), then the output will show a range and sentence "wrong answer, guess smaller" 1<?<50. If my next attempt(ex:30) is too small, the output will show a new range and sentence "wrong answer, guess larger" 30<?<50. If I guess right, then the output will show "bingo answer is X(my guess)"
The below is what I have right now. Please help me fix it. Thanks!
The program will generate number from 1 to 99 and I have to input the answer first then input my guess. If my guess(ex:50) it larger than the answer(ex:45), then the output will show a range and sentence "wrong answer, guess smaller" 1<?<50. If my next attempt(ex:30) is too small, the output will show a new range and sentence "wrong answer, guess larger" 30<?<50. If I guess right, then the output will show "bingo answer is X(my guess)"
The below is what I have right now. Please help me fix it. Thanks!
import random min=1 max=99 random.randint(1,99) correct_answer = int(input()) print("1<?<100") guess= int(input()) while guess != correct_answer: more_attempts=int(input()) if guess>correct_answer: print("wrong answer, guess smaller","{0}<?<{1}".format(min,max),sep='\n') elif guess<correct_answer: print("wrong answer, guess larger", "{0}<?<{1}".format(min,max),sep='\n') else: guess == correct_answer print("bingo answer is",guess) break