Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Guess the Number" game
#1
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!
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
Reply


Messages In This Thread
"Guess the Number" game - by CTT - Jul-17-2017, 12:43 PM
RE: "Guess the Number" game - by ichabod801 - Jul-17-2017, 01:13 PM
RE: "Guess the Number" game - by snippsat - Jul-17-2017, 04:16 PM
RE: "Guess the Number" game - by CTT - Jul-18-2017, 10:50 AM
RE: "Guess the Number" game - by ichabod801 - Jul-18-2017, 12:13 PM
RE: "Guess the Number" game - by CTT - Jul-23-2017, 05:22 PM
RE: "Guess the Number" game - by snippsat - Jul-23-2017, 05:59 PM
RE: "Guess the Number" game - by ichabod801 - Jul-23-2017, 08:41 PM
RE: "Guess the Number" game - by CTT - Jul-24-2017, 03:23 AM
RE: "Guess the Number" game - by ichabod801 - Jul-24-2017, 03:52 AM
RE: "Guess the Number" game - by CTT - Jul-24-2017, 02:22 PM
RE: "Guess the Number" game - by ichabod801 - Jul-24-2017, 02:54 PM
RE: "Guess the Number" game - by CTT - Jul-24-2017, 03:19 PM
RE: "Guess the Number" game - by ichabod801 - Jul-24-2017, 04:56 PM
RE: "Guess the Number" game - by sylas - Jul-26-2017, 11:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Guess the word game help jackthechampion 3 3,172 Sep-06-2023, 06:51 AM
Last Post: Pedroski55
  Unable to count the number of tries in guessing game. Frankduc 7 2,100 Mar-20-2022, 08:16 PM
Last Post: menator01
  Ask again if wrong guess with While. EduPy 4 2,390 Oct-21-2021, 07:46 PM
Last Post: menator01
  I guess it's about print tsavoSG 2 2,232 Feb-08-2021, 08:34 PM
Last Post: steve_shambles
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,950 Jun-18-2020, 04:59 PM
Last Post: QTPi
  guessing the number game go127a 6 4,999 Apr-27-2019, 01:23 PM
Last Post: go127a
  Generating number of objects for a game kom2 3 2,735 Apr-18-2019, 02:04 PM
Last Post: dan789
  can't figure out problem with number guess Galoxys 4 3,505 Oct-29-2018, 01:45 PM
Last Post: snippsat
  Guess a number Ameen 5 13,334 Apr-03-2018, 01:20 PM
Last Post: snippsat
  Guess Random Number Why i m not able to enter input Nithya Thiyagarajan 6 8,430 Jan-07-2018, 04:26 AM
Last Post: squenson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020