Когда кто-то говорит что-то еще в replay (), кроме «нет» или «да», он начинает ход хоста по какой-то причине или даже нет.
Я все еще учусь, это мой второй проект, любые комментарии?Я перепробовал много вещей, но все равно не работает.
# Blackjack game
import random
global playername, nameofplayer
nameofplayer = input('Enter your name').capitalize()
print ('Hello,', str(nameofplayer))
class Player():
def __init__(self, banktotal):
self.banktotal = banktotal
# adds an amount to the bank
def addtobank(self, bankadd):
self.banktotal += bankadd
# removes an amount from the bank
def subfrombank(self, subbank):
self.banktotal -= subbank
def rolldice():
global playerhand
playerhand = 0
print('Your Current hand: ' + str(playerhand))
playerhand = 0
print ('...')
print ('Rolling the dice for you')
dice = list(range(1,7))
while playerhand <= 21:
rolled = random.choice(dice)
print('Your Current hand: ' + str(playerhand))
hitstick = str(input('Hit or Stick?').capitalize())
if hitstick == 'Hit':
print('You chose to hit!')
playerhand += rolled
elif hitstick == 'Stick':
print('Your exit hand: ' + str(playerhand))
break
elif hitstick != 'Hit' or 'Stick':
print('Enter a valid argument')
else:
print('Your Current hand: ' + str(playerhand))
print ('Busted, Host Wins!')
print('Reducing 100$ from your account')
playername.banktotal -= 100
print('Your bank balance: ' + str(playername.banktotal))
replay()
def hostchance():
hosthand = 0
print ('Current host hand: ' + str(hosthand))
dice = list(range(1, 7))
while hosthand <= playerhand:
rolled = random.choice(dice)
hosthand += rolled
print('Rolling the dice for the host')
print ('Current host hand: ' + str(hosthand))
if hosthand < playerhand:
pass
elif hosthand == playerhand:
print ('Its a draw!')
break
elif hosthand > playerhand and hosthand < 22:
print('Host Wins!')
print('Reducing 100$ from your account')
playername.banktotal -= 100
break
if hosthand < playerhand or hosthand > 21:
print (str(nameofplayer) + ' Wins!')
print('Adding 100$ to your account')
playername.banktotal += 100
playername = Player(1000)
def game():
print ('Your bank balance: ' + str(playername.banktotal))
rolldice()
something = input('Enter anything for the host to start his turn')
print (something)
print('Host Chance')
hostchance()
print ('Your bank balance: ' + str(playername.banktotal))
def replay():
print('Do you want to play again?')
replay = input('Input with yes or no: ').lower()
if replay == 'yes':
game()
elif replay == 'no':
pass
game()
replay()