Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: SOLVED: Coding Question: IT SEEMS SO SIMPLE! (Python)  (Read 1081 times)

nomnum

  • Bay Watcher
  • Spayships
    • View Profile
    • Eighteen Pixels
SOLVED: Coding Question: IT SEEMS SO SIMPLE! (Python)
« on: October 26, 2012, 03:24:22 pm »

Nom here,

I am trying to make a simple Black Jack game, but i am having trouble with if functions relating to generated numbers.
Being Python isnt really important because this simple feature is on most programming languages.

So what did i do wrong?

Ideally after receiving a 2 as the random number it should print 2 again.
The strange part is the elif function for 3 works... i think it has to do with me having OR in the argument.



« Last Edit: October 26, 2012, 04:24:08 pm by nomnum »
Logged
One does not simply...
Manage a dwarven fortress.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: Coding Question: IT SEEMS SO SIMPLE! (Python)
« Reply #1 on: October 26, 2012, 03:26:38 pm »

(1 or 2) doesn't work.  It would have to be:

if randy == 1 or randy == 2:

What is happening currently is (1 or 2) resolves to "true", because or is a boolean operator and numbers are treated as true.  Then you are comparing (randy == true).
« Last Edit: October 26, 2012, 03:29:41 pm by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

nomnum

  • Bay Watcher
  • Spayships
    • View Profile
    • Eighteen Pixels
Re: Coding Question: IT SEEMS SO SIMPLE! (Python)
« Reply #2 on: October 26, 2012, 03:45:36 pm »

(1 or 2) doesn't work.  It would have to be:

if randy == 1 or randy == 2:

What is happening currently is (1 or 2) resolves to "true", because or is a boolean operator and numbers are treated as true.  Then you are comparing (randy == true).

Thanks! that was helpful. Now in the case of a real blackjack game, there will obviously be more than 3 cards, so how do you do a "thorugh" or "between" test?
For example, i thought it was (but am incorrect)

if randy == (1:10):
    etc, etc, etc

<!-- Meaning that if randy is from 1 to 10, run function --!>

Thanks in advance
Logged
One does not simply...
Manage a dwarven fortress.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: Coding Question: IT SEEMS SO SIMPLE! (Python)
« Reply #3 on: October 26, 2012, 03:50:47 pm »

I'd do something like:

if(randy >= 1 and randy <= 10)

Which is "If randy is greater than or equal to 1 and randy is less than or equal to 10".
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

nomnum

  • Bay Watcher
  • Spayships
    • View Profile
    • Eighteen Pixels
Re: Coding Question: IT SEEMS SO SIMPLE! (Python)
« Reply #4 on: October 26, 2012, 04:23:53 pm »

I'd do something like:

if(randy >= 1 and randy <= 10)

Which is "If randy is greater than or equal to 1 and randy is less than or equal to 10".

Thanks that worked! IOU1 ;)
Logged
One does not simply...
Manage a dwarven fortress.