Skip to content
Sign upLog in
← Back to Community

I need help with a script that doesn't seem to work!

Profile icon
Bobo48

I am making a gambling script in Python and it seems to always throw out the same answer, thank you for help. The coin flip script seems to work but the other one doesn't. Sorry if this seems like a stupid question I am new to this.
Script:
#START
a = random.randint(1, 2)
cc = random.randint(1, 12)
#COINFLIP MINIGAME
def coin_flip(side, bet):
if a == 1 and side == "Heads":
return "Heads, you won " + str(bet * 2) + " dollars!"
elif a == 1 and side == "Tails":
return "Heads, you lost " + str(bet) + " dollars!"
elif a == 2 and side == "Tails":
return "Tails, you won " + str(bet * 2) + " dollars!"
elif a == 2 and side == "Heads":
return "Tails, you lost " + str(bet) + " dollars!"
#DICE MINIGAME
def gamble(side, bet):
if cc == odd_numbers and side == "Odd":
return "Odd, you won " + str(bet * 2) + " dollars!"
elif cc == odd_numbers and side == "Even":
return "Odd, you lost " + str(bet) + " dollars!"
elif cc == 2 or 4 or 6 or 8 or 10 or 12 and side == "Even":
return "Even, you won " + str(bet * 2) + " dollars!"
elif cc == 2 or 4 or 6 or 8 or 10 or 12 and side == "Odd":
return "Even, you lost " + str(bet) + " dollars!"

print(coin_flip("Heads", 555))
print(gamble("odd", 20))

Voters
Profile icon
sojs
Profile icon
kevinanderson31
Profile icon
Bobo48
Comments
hotnewtop
Profile icon
launcherman08

Can you add the repl pls?

Profile icon
sojs

Your error is that you put some "and" and "or" statements in quotes

Profile icon
Bobo48

@sojs
Nah that was me trying something out, I fixed it like 4 days ago by adding brackets after the and therefore making it so it doesn't think that if cc is anything after the or it can print it out. Thanks for trying to help though!(sorry for the late response)

Profile icon
sojs

@Bobo48
Ah, okay.

Profile icon
sojs
Profile icon
Bobo48
Profile icon
sojs

@Bobo48
Maybe it's a problem with your computer? I seemed to work fine for me.

Screenshot 2019-09-13 at 12.28.37 PM


Screenshot 2019-09-13 at 12.28.15 PM

Screenshot 2019-09-13 at 12.27.42 PM

Profile icon
kevinanderson31

a = random.randint(1, 2)
cc = random.randint(1, 12)
#COINFLIP MINIGAME
def coin_flip(side, bet):
if a == 1 and side == "Heads":
return "Heads, you won " + str(bet + 2) + " dollars!"
elif a == 1 and side == "Tails":
return "Heads, you lost " + str(bet) + " dollars!"
elif a == 2 and side == "Tails":
return "Tails, you won " + str(bet + 2 ) + " dollars!"
elif a == 2 and side == "Heads":
return "Tails, you lost " + str(bet) + " dollars!"

#take note that when you have a " : " you have to indent the next line

Profile icon
Bobo48

@kevinanderson31
Oh I know I am not having problems with the coinflip the thing that's wrong is the dice minigame.

Profile icon
Bobo48

Still need help

Profile icon
Bobo48

a little further up where I didn't copy there is "import random" and ignore the odd numbers thing it's supposed to be " 1 or 3 or 5 or 7 or 9 or 11

Profile icon
Bobo48

Sorry the code kind of removed the spacing in the beginning. all the spacing is right in the code btw

Profile icon
Bobo48

Also the (bet 2) is actually (bet * 2).

Profile icon
AzureScripts

May you link the repl you are working in? I may be able to get a better look !

@Bobo48

Profile icon
Bobo48
Profile icon
Bobo48

@AzureScripts
Sorry if it's something really simple I've been learning to program only for 3 days so far

Profile icon
AzureScripts

What is the issue exactly?

@Bobo48

Profile icon
Bobo48

@AzureScripts
The gamble function ALWAYS prints out a win even if it's an even number and you picked odd.

Profile icon
AzureScripts

@Bobo48
I got an idea, make a multiplayer repl :)

Profile icon
AzureScripts

@Bobo48
Hey, sorry for disappearing. College went into lunch and i had to leave the computer room lol

Profile icon
Bobo48
Profile icon
AzureScripts

@Bobo48
I do have 30 minutes before lunch ends if you want to have a round 2?

Profile icon
Bobo48

@AzureScripts
Sure I don't really care I've been thinking about what's wrong with it the whole time you were gone

Profile icon
AzureScripts

@Bobo48
Start it up, i'll join back

Profile icon
Bobo48

@Bobo48
Couldn't figure anything out

Profile icon
Bobo48

@AzureScripts
It should be up