Python Forum
Money Global Variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Money Global Variable
#9
(Apr-12-2019, 12:59 AM)loomski Wrote: But then he will have to keep doing money = old_witch(money) and after that, money = blacksmith(money) and then every single time he wants to make a new function where he adds money or decrements money he will have to keep reassigning?

Yes, which will make it clear that money is being modified by that function call. If he's just got a bunch of oldwitch() and blacksmith(), it is not clear at all that money is used or modified by those functions. And when he runs into a bug with money changing or not changing as expected, it's going to be that much harder track down the bug and figure it out.

(Apr-12-2019, 12:59 AM)loomski Wrote: I don't know, maybe for this particular thing where he's just calling 2 functions and checking them maybe this might be the "best" way (lol) but if he wants to have a hundred of those types of functions, I don't know.

If he wants to have hundreds of these types of functions, then the hundreds of functions are a problem, not having to pass, return, and assign values. At that point he needs a generic function for handling purchases, and he needs to move the distinction between witches and blacksmiths into some data. At that point he should also switch to OOP, and money should become an attribute of the Player class, which is in turn an attribute of the Game class.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Money Global Variable - by saturnstars - Apr-11-2019, 07:46 PM
RE: Money Global Variable - by metulburr - Apr-11-2019, 08:03 PM
RE: Money Global Variable - by loomski - Apr-11-2019, 08:35 PM
RE: Money Global Variable - by ichabod801 - Apr-11-2019, 09:06 PM
RE: Money Global Variable - by loomski - Apr-11-2019, 09:33 PM
RE: Money Global Variable - by perfringo - Apr-11-2019, 09:34 PM
RE: Money Global Variable - by ichabod801 - Apr-11-2019, 10:07 PM
RE: Money Global Variable - by loomski - Apr-12-2019, 12:59 AM
RE: Money Global Variable - by ichabod801 - Apr-12-2019, 10:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I have this coding exercise to find how much money take Barrack Obama and Romney Mitt vasiliskarv 1 484 Mar-19-2024, 08:24 PM
Last Post: deanhystad
  Need help on Hands-On - Multithreading in Python using global variable ashishsme14 5 2,731 May-21-2020, 04:38 AM
Last Post: ndc85430
  Banking system - transferring money 3DEN 2 9,008 Dec-13-2019, 09:13 AM
Last Post: 3DEN
  Global Variable issue AnOrdinaryFolk 1 2,325 Feb-06-2018, 07:26 PM
Last Post: micseydel
  Money Bags Program PythonNoob123 2 7,868 Jan-23-2017, 10:42 PM
Last Post: PythonNoob123

Forum Jump:

User Panel Messages

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