vendredi 1 novembre 2019

Why is the else statement not executed?

import random

words = ["Rock", "Paper", "Scissors"]

wins, loss = 0, 0

while True:

    word = random.choice(words)

    ur_word = input("Rock, Paper, Scissors..: ")

    print("\nComputer: {0}\nYou: {1}\n".format(word, ur_word))

    if word == ur_word:
        print("Tie!")
        continue
    elif ur_word == 'q':
        break
    elif word == 'Rock':
        if ur_word == 'Paper':
            print("You won!")
            wins += 1
        elif ur_word == 'Scissors':
            print("You lost!")
            loss += 1
    elif word == 'Paper':
        if ur_word == 'Rock':
            print("You lost")
            loss += 1
        elif ur_word == 'Scissors':
            print("You won!")
            wins += 1
    elif word == 'Scissors':
        if ur_word == 'Rock':
            print("You won!")
            wins += 1
        elif ur_word == 'Paper':
            print("You lost!")
            loss += 1
    else:                                        <<<<---------///----------HERE------------///----
        print("Please enter a valid input.")


    if wins == 3:
        print("\n\tYou won the entire game of three rounds!")
        break
    elif loss == 3:
        print("\n\tYou lost the entire game of three rounds!")
        break

**Now, my question is: why does the selected else statement not execute when I enter an arbitrary value like "74n9wndwekf"?

A guy told me that you cannot execute if and elif statements after an else statement, and also that you cannot execute your code after a break statement. I don't understand what he meant and I don't know whether this information is of any value to you.**

Aucun commentaire:

Enregistrer un commentaire