Python Forum
please help me improve this minigame
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
please help me improve this minigame
#6
If you compare values in Python using "and" and "or" like this:
if (player1 and player2) == 911:
if (player1 or player2) > 10:
a Boolean comparison (True/False) is made. In this case, any nonzero number and non-empty string is True. When "and" comparison is used, values are checked sequentially and if they are all True, the last value is returned (in this case value of player2). In case of "or", values are checked sequentially, and when first value which is True is encountered, comparison stops and that value is returned (it may be player1 or player2). It works the same way even if you chain 100 values to be compared instead of just 2. There is no real science behind this, it's just how Python works.

There is maybe a bit of an optimization trick here. If you compare by "and", you can put values that are most likely to be False first, so the checking is over quicker in case they are False. Likewise with "or", you can put values that are most likely to be True first, so checking can be over quicker.
I don't think this is very relevant for your particular code, but just an extra info in case you find it useful to know :)
Reply


Messages In This Thread
please help me improve this minigame - by Naito - Jan-21-2019, 10:31 AM
RE: please help me improve this minigame - by Naito - Jan-21-2019, 11:28 AM
RE: please help me improve this minigame - by Naito - Jan-21-2019, 11:47 AM
RE: please help me improve this minigame - by j.crater - Jan-21-2019, 12:54 PM
RE: please help me improve this minigame - by Naito - Jan-21-2019, 03:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Minigame Collection with Menu textmonster404 1 3,551 Feb-20-2017, 02:11 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

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