vendredi 12 novembre 2021

Why is elif not registering when I run the code? Simple Dice Game

I'm a beginner in python and I'm making a dice game for practice. The computer (ai) rolls dice against the player and then the results are compared for who is the winner. However, when both of the results are the same (e.g. player rolls a 4 and ai rolls a 4) the program says "you win!" even though I put in an elif statement for a tie. Any help?


import random
import time

player = random.randint(1,6)
print("You rolled " + str(player))

ai = random.randint(1,6)
print("The computer rolls...")
time.sleep(2)
print("The computer has rolled a " + str(player))

if player > ai:
 print("You win")

elif player == ai:
 print("Tie game")

else: 
 print("You lose")

I've already tried to put else before elif but then I get a syntax error?




Aucun commentaire:

Enregistrer un commentaire