Python newbie here. I’m trying to create a black jack game in which the user plays against the computer. I think where I’m having trouble is with the if, elif statements here. What I want to know is, what happens when none of the criteria of any of the if and elif statements are met when I don’t have an else statement? Is it problematic here not to have an else statement?
def game_winner(n):
p_wins = 0
d_wins = 0
for i in range(n):
player_sum = player_game()
dealer_sum = dealer_game()
if player_sum > dealer_sum and player_sum <= 21:
p_wins = p_wins + 1
elif dealer_sum > 21 and player_sum <= 21:
p_wins = p_wins + 1
elif player_sum > 21 and dealer_sum <= 21:
d_wins = d_wins + 1
elif dealer_sum > player_sum and dealer_sum <= 21:
d_wins = d_wins + 1
return p_wins, d_wins
If none of the conditions are met then none of the conditionals in any of the
iforelifblocks are executed. If it is ok that neither the computer or the player wins in a round, then it’s fine. Otherwise you should include anelsestatement to cover that case.