Skip to content

Instantly share code, notes, and snippets.

@zemmyang
Created December 16, 2020 19:26
Show Gist options
  • Save zemmyang/8da1b85acd64f483d1c82a4725e004c0 to your computer and use it in GitHub Desktop.
Save zemmyang/8da1b85acd64f483d1c82a4725e004c0 to your computer and use it in GitHub Desktop.
Simple Betting Game in Python
import random
def intro_banner():
s = "Welcome to the Game!"
print(s)
def game_over():
s = "Game Over. Bye!"
print(s)
def main():
intro_banner()
playername = input('Player Name >> ')
money = 50
print("Welcome to the game, " + playername + ". Your starting amount is " + str(money) + ' Gold.')
keepplaying = True
while keepplaying:
bet = input("Place your bet >> ")
isbetnotvalid = int(bet) > money or int(bet) < -1
while isbetnotvalid:
print("Please enter a valid bet.")
bet = input("Place fix your bet >> ")
isbetnotvalid = int(bet) > money or int(bet) < -1
bet = int(bet)
player_card = random.randint(1, 12)
cpu_card = random.randint(1, 12)
print("Your card is " + str(player_card) + ". CPU card is " + str(cpu_card) + ".")
if player_card == cpu_card:
print("It's a DRAW! CPU wins because that's how it is.")
money = money - bet
elif player_card > cpu_card:
print("You win " + str(bet) + " Gold!")
money = money + bet
else:
print("CPU wins! You lose " + str(bet) + " Gold!")
money = money - bet
if money < 0:
print("You're out of money!")
game_over()
keepplaying = False
else:
print("Your money is now " + str(money) + " Gold.")
ask = input("Do you want to keep playing? [y/N] >> ")
if ask == 'y' or ask == 'Y':
keepplaying = True
else:
print("You're leaving with " + str(money) + " Gold. Bye.")
game_over()
keepplaying = False
main()
@SpringfieldC
Copy link

SpringfieldC commented Oct 22, 2023

Interesting and easy-to-understand code for gambling games, thank you very much. I love Python for its line-by-line execution. It simplifies testing and debugging of the code. If you're interested in the topic of gambling, I can recommend football betting sites not on Gamstop that are featured on https://notgamstop.com/betting-sites-not-on-gamstop/football/. It's an interesting website, and I need to explore everything it has to offer further. I ended up here as I started to recall my programming skills, particularly in Python. It's great that this language has a large and active community of developers.

@jasicarose75
Copy link

jasicarose75 commented Dec 9, 2023

I love this. I recently saw some code written by a programmer. His skill was simply amazing; the best casino site will come out. I myself sometimes like to play, I recently read about the no deposit bonus, I used the information online casino philippines with free signup bonus here. I want to write something similar myself in the near future. All I need is an idea, so far this is the only problem I have and a couple of technologies.

@dockcole11
Copy link

That's a great code. I am especially glad that you can use the code to write not only programs, but also bots for Discord or Telegram, for example. There are also gambling bots for Discord. If you're a coding or gambling enthusiast seeking an interactive and dynamic experience on Discord, exploring gambling bots adds a new dimension to your virtual adventures. Discord, known for its versatility, hosts a variety of engaging bots. For an insider's guide to the original site highlighting the best Discord gambling bots, check out the recommendations and features that elevate your gaming sessions. These bots introduce an element of chance and fun, enhancing the social gaming atmosphere within the Discord community, making it a thrilling space for gamers to explore and enjoy.

@BlakeSipple
Copy link

Thanks for posting. It looks good so far. Carry on!

@Ngwacarl009
Copy link

print("It's a DRAW! CPU wins because that's how it is.")😂😂😂 if not great code I appreciate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment