feat: Initial commit
This commit is contained in:
60
blackjack.py
Normal file
60
blackjack.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from random import randint
|
||||
|
||||
cardArray = []
|
||||
|
||||
|
||||
def resetDeck():
|
||||
global cardArray
|
||||
cardArray = []
|
||||
for i in range(1, 9):
|
||||
for x in range(4):
|
||||
cardArray.append(i)
|
||||
|
||||
for x in range(12):
|
||||
cardArray.append(10)
|
||||
|
||||
|
||||
def genCard():
|
||||
global cardArray
|
||||
n = randint(0, len(cardArray) - 1)
|
||||
x = cardArray[n]
|
||||
cardArray.pop(n)
|
||||
return x
|
||||
|
||||
|
||||
while True:
|
||||
resetDeck()
|
||||
|
||||
computerSum = genCard()
|
||||
print("La carta scoperta del banco è ", computerSum)
|
||||
computerSum += genCard()
|
||||
|
||||
playerSum = genCard() + genCard()
|
||||
|
||||
while True:
|
||||
print("La somma delle tue carte è pari a ", playerSum)
|
||||
if playerSum > 21:
|
||||
print("Hai perso")
|
||||
break
|
||||
|
||||
cont = input("Hit or stay? ") == "hit"
|
||||
if cont:
|
||||
playerSum += genCard()
|
||||
else:
|
||||
break
|
||||
|
||||
if playerSum > 21:
|
||||
print("\n"*4)
|
||||
continue
|
||||
|
||||
while computerSum < 17:
|
||||
computerSum += genCard()
|
||||
|
||||
print("La somma delle carte del banco è ", computerSum)
|
||||
|
||||
if computerSum > 21 or playerSum > computerSum:
|
||||
print("Hai vinto")
|
||||
else:
|
||||
print("Hai perso")
|
||||
|
||||
print("\n"*4)
|
||||
Reference in New Issue
Block a user