Simple Roulette and Coinflip with Python | LBOET | HOX
Hello people and welcome.
In this tutorial i will show you how to easily make roulette and coinflip programs in python.
Firstly our balance.txt file has a number in it, thats your balance, you dont need $ or anything, just a number,
for example i have: 100
Then
STARTME.bat:
---------------
color 0a
cls
:loop
roulette.py
timeout 5
cls
goto loop
---------------
RESTARTBALANCE.bat :
---------------
@ECHO off
color 0a
ECHO 100 > balance.txt
---------------
The ROULETTE CODE :
---------------
import random
lista = []
lista3 = []
def Main():
allnumbers = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
randAN = random.choice(allnumbers)
f = open("balance.txt","r")
fre = f.read()
kljuc = int(fre)
f.close()
kljuc2 = kljuc
print("Your balance : {}$".format(kljuc2))
betamount = int(input("How much do you want to bet?\n>"))
remaining_balance = kljuc2 - betamount
print("Betting ",betamount,"Balance remaining:",remaining_balance,"$")
f = open("balance.txt","w+")
f.write("%s"% remaining_balance)
f.close()
nullquestion = str(input("Do you want to bet:\n1.A color\n2.A number\n>"))
if nullquestion.startswith("1"):
print("Pick a color:\n1.Black\n2.Red")
usernumbers = []
inpp = str(input(">"))
if inpp == "1":
print("You bet black")
usernumbers = [2,4,6,8,10,12,14]
if randAN in usernumbers:
print("You won!")
betamount *= 2
elif randAN not in usernumbers:
print("You lost.")
betamount -= betamount
elif inpp == "2":
print("You bet red.")
usernumbers = [1,3,5,7,9,11,13]
if randAN in usernumbers:
print("You won!")
betamount *= 2
elif randAN not in usernumbers:
print("You lost.")
betamount -= betamount
else:
print("invalid bet")
elif nullquestion.startswith("2"):
question = int(input("Enter the number you want to bet:"))
if question == randAN:
print("You won.")
betamount *= 7
else:
print("You lost")
betamount -= betamount
print("Roulette rolled {}.\n".format(randAN))
lista3.append(remaining_balance)
keyey3 = str(lista3)
keyey3 = keyey3.replace("[","")
keyey3 = keyey3.replace("]","")
keyey3 = keyey3.replace("'","")
finalkey3 = int(keyey3)
lista.append(betamount)
keyey = str(lista)
keyey = keyey.replace("[","")
keyey = keyey.replace("]","")
keyey = keyey.replace("'","")
notfinalkey = float(keyey)
finalkey = int(notfinalkey)
moneywon_moneylost = finalkey3 + finalkey
print("Total balance :",moneywon_moneylost)
f = open("balance.txt","w+")
f.write("%s"% moneywon_moneylost)
f.close()
Main()
------------------------------------------------------------------------------------------
Coinflip has the same .txt file as roulette but its called DATA.txt.
And the COINFLIP CODE is HERE :
----------------------------------
import random
def Main():
f = open("data.txt","r")
fre = f.read()
kljuc = int(fre)
f.close()
kljuc2 = kljuc
kljucni = 0
kljuciv = 0
invite = int(input("What do you wanna bet?\n1.Heads\n2.tails?\n>"))
if invite == 1:
kljucni += 1
elif invite == 2:
kljucni += 2
lista = [1,2]
key = random.choice(lista)
if key == 1:
print("Coin flipped Heads")
kljuciv += 1
elif key == 2:
print("Coin flipped Tails")
kljuciv += 2
else:
print("...")
if kljucni == key:
print("You won !")
print("Adding double balance.")
kljuc2 += 10
f = open("data.txt","w+")
f.write("%s"% kljuc2)
f.close()
print("Current balance:",kljuc2)
Main()
else:
print("You lost..")
print("Removing from balance...")
kljuc2 -= 10
f = open("data.txt","w+")
f.write("%s"% kljuc2)
f.close()
print("Current balance:",kljuc2)
Main()
Main()
print("Your current balance is :",fre)
#f.write("This is line %d\r\n" % (i+1))
#f.close()
---------------
Comentarios