jeudi 11 avril 2019

how to use an if else statement in another while loop

I am new to coding. I want to try writing a simple rock paper scissors game. But I can't figure out how to end the game

in the end of this program if the user input is wrong i want to go to the end variable again. i tried with the commented lines but its not working.

player1 = input("What is player 1's name ? ")
player2 = input("What is player 2's name ? ")

player1 = player1.title()
player2 = player2.title()
while True:
    print(player1 + " What do you choose ? rock / paper / scissors : ")
    a = input()

    print(player2 + " What do you choose ? rock / paper / scissors : ")
    b = input()
    if a == "rock" and b == "scissors" :
        print(player1, "won !!!")
    elif a == "scissors" and b == "rock":
        print(player2, "won !!!")

    elif a == "paper" and b == "rock":
        print(player1, "won !!!")
    elif a == "rock" and b == "paper":
        print(player2, "won !!!")

    elif a == "scissors" and b == "paper":
        print(player1, "won !!!")
    elif a == "paper" and b == "scissors":
        print(player2, "won !!!")

    elif a == b:
        print("Its a tie :-(")

    elif a or b != "rock" or "paper" or "scissors":

        print("Wrong input, Try again")
    end = input("Do you want to play again ? yes/no ") == "yes"
    if input == "yes":
        continue
    else:

        print('''

        GAME OVER''')
        break
#    elif input != "yes" or "no":
#        print("Wrong input, Try again. yes or no ?")


i expect it to end game if the input is "no" and restart the game if input is "yes" if the input is not correct i want the prompt to appear again

Aucun commentaire:

Enregistrer un commentaire