Python Forum
Asking for help in my code for a "Guess the number" game.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Asking for help in my code for a "Guess the number" game.
#6
One thing to ask from yourself - is your objective to meet deadline and move on with your life or learn to program?

If first then (based on your moral values) cheating is an option. However, if you intend to learn to program then you should start yourself from scratch.

jefsummers provided one way how to split 'big task' into smaller chunks. It doesn't matter if you use this or create your own 'algorithm' - you have to solve all these small tasks one after another.

Just and idea:

You should test your code as you go. For beginner 'testing' means that you write small chunk of code, run it and observe if it's working as expected. If so you add new lines of code and repeat.

Write code into .py file, run it from terminal in interactive mode and check whether all names, values etc are as you excpect them to be. You should be able to understand error messages as well.

Lets write two first lines of code into file (guessing_game.py) and observe what happens:

import random


player_win == False
Now from terminal cd into directory where your guessing_game.py is. Then enter:

python -i guessing_game.py (or python3 or something else depending how Python is set up on your computer)

This will run the file and keep Python interactive session alive. But in this case it doesnt matter. You will see:

Output:
Traceback (most recent call last): File "guessing_game.py", line 4, in <module> player_win == False NameError: name 'player_win' is not defined
What did happen? You check whether player_win is False. As player_win is not defined you will get NameError. If you intend to assing False to player_win then you should write player_win = False. If you make changes in file and run it again then nothing happens except Python interactive prompt appears in terminal. You can check the value of player_win:

>>> player_win
False
Now you take next step and repeat process until you have working code.

Instead of .py file and terminal one can use Jupyter Notebook / JupyterLab.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
RE: Asking for help in my code for a "Guess the number" game. - by perfringo - Aug-14-2019, 12:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help - random number/letter guessing game juin22 1 3,278 Aug-16-2020, 06:36 AM
Last Post: DPaul
  Dynamically chosing number of players in a "game" nsadams87xx 5 4,349 Jul-17-2020, 02:00 PM
Last Post: deanhystad
  Can someone help me optimize this game for large number of strings Emekadavid 13 5,252 Jul-06-2020, 06:16 PM
Last Post: deanhystad
  making a guessing number game blacklight 1 2,264 Jul-02-2020, 12:21 AM
Last Post: GOTO10
  Prime number code ryfoa6 3 2,998 Mar-21-2020, 12:23 AM
Last Post: ryfoa6
  Trouble interpreting prime number code ryfoa6 1 2,346 Mar-20-2020, 03:47 PM
Last Post: stullis
  Guess the number game jackthechampion 5 3,296 Mar-07-2020, 02:58 AM
Last Post: AKNL
  restarting game code zyada7med 5 4,816 Sep-03-2019, 09:24 PM
Last Post: ichabod801
  Guess a number game Drone4four 4 5,419 Nov-16-2018, 03:56 AM
Last Post: Drone4four
  Code: Creating a basic python game? searching1 5 3,554 Nov-12-2018, 05:18 AM
Last Post: searching1

Forum Jump:

User Panel Messages

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