Games of Chance Challenge Project (Python)

Hello CodeCademy Community
Here is my code:

Have a great day

Here is an interactive version of the challenge.

1 Like

This was a lot of fun to do. I went through multiple drafts of my roulette code before settling on something I liked. I wound up researching lists, character positions in strings, and converting strings to integers (and vice versa) to make it work for me. What a challenge!

Anyways, here’s my code, including all possible bets/outcomes for roulette. I hope you enjoy it as much as I did!

Here is my code… Pretty happy with how it turned out. The only missing feature is betting on ranges for Roulette, eg. bet on column (1-12) for a 2:1 Payout… but I did include Odd, Even, Straight Up bets and both 0 and 00.

Any feedback would be appreciated… I don’t think the way I did Card War was very efficient, but I really wanted it to display a Card like you would IRL… (Nobody pulls a 13, they pull a KING)

1 Like

I had to do some research, but I think I came up with efficient ways to do the card war with actual card names, and incorporate Highs/Lows/Dozens into the roulette. Check it out if you want.

https://gist.github.com/702e50e7f4a1a400ff93521d690f7a84

3 Likes

Here is my project! Please look an give feedback :slight_smile:

I just realized I have extra roulette number “37” lol oh, well!

Here’s my take on this exercise, great learning experience and also very proud for a noob coder :slight_smile:

Good luck! :+1:

1 Like

Just tried it off platform and it’s awesome! Will be learning a lot from your version, thanks! :sunglasses: :+1:

Here is my try, i am proud of it too, as this are my beginnings

Can anyone tell me what’s wrong with my code for the coin flip? It’s basically about the error in line 23. I understand that this is the way to call the function while updating the amount of money but why doesn’t it work?

here:

money += coin_flip(2, 45)

the function returns a string, then you try to add string and integer together, how should that be resolved? Python doesn’t know, so it throws an error

I think I got it right this time, I’m so relieved. Thanks a lot!!!

It seems, in your game, people can only win money. You always return bet_amount (a positive value) and you always increase money

You’re right, now I see it. In order to make it negative I just added a “-” when returning “bet_amount” and it seems to work just fine. Hopefully now I can move on.

Thank’s for all of the tips :+1:

that is indeed the best solution. Well, if you tested all scenarios and covered everything, you should be able to move on indeed :slight_smile:

I’ve tested all scenarios and added a couple of print statements. It’s a lot more fun dealing with this than earlier! I just finished the code for the dice game and it works really well :slight_smile:

here is my solution to th first problem, although i used a while loop.
import random

money = 100

#Write your game of chance functions here

guess = random.randint(1,2)

def dice(guess,player_guess,bet):
while True:
if guess == player_guess:
return “you won” + str(bet)
break
else:
return "you lossed " + str(bet)

print(dice(guess,1,40))

import random

money = 100

#Write your game of chance functions here

guess = random.randint(1,2)

def dice(guess,player_guess,bet):
while True:
if guess == player_guess:
return “you won” + str(bet)
break
else:
return "you lossed " + str(bet)

print(dice(guess,1,40))

here is my code:
link to my code