mercredi 30 janvier 2019

How can I optimize the loop and condition statements?

winner = False

def player():
    global winner
    while winner==False:

        print("player 1: please choose rock/paper/scissor !")
        choice1 = input()
        print("player 2: please choose rock/paper/scissor !")        
        choice2 = input()

        if choice1!=choice2:
            if choice1=="rock" and choice2=="scissor" :
                print("player 1 is the winner, Congrats!!")

            elif choice1=="rock" and choice2=="paper" :
                print("player 2 is the winner, Congrats!!")

            elif choice2=="rock" and choice1=="scissor" :
                print("player 2 is the winner, Congrats!!")

            elif choice2=="rock" and choice1=="paper" :
                print("player 1 is the winner, Congrats!!")

            elif choice1=="scissor" and choice2=="paper" :
                print("player 1 is the winner, Congrats!!")

            elif choice1=="paper" and choice2=="scissor" :
                print("player 2 is the winner, Congrats!!")
        else:
            print("its a draw")


        print("do you want to start a new game?,yes or no")
        answer = input()
        if answer=="yes":
            print("lets start another game!")
            winner = False
        elif answer=="no":
            print("see you next time!")
            winner = True


player()

as you can see there is too much inefficient if statements in my code ,how can i minimize them if possible

Aucun commentaire:

Enregistrer un commentaire