samedi 17 février 2018

Continued while loop ignoring if statements

So I have a rock paper scissors game. Upon the user completing their designated # of rounds, they are prompted whether or not they want to continue, and how many rounds they want to play this time. However, no matter what # I choose, the loop goes on forever. ignoring the if statements to end the loop. Heres the while loop portion of my code:

while again == True:

    print("It is ",name,"'s", " turn. What do you pick (R)ock, (P)aper, or (S)cissors?: ", sep = '',end = "")
    print()
    print()
    user = str.lower(input())
    print()

    if user != "s" and user != "r" and user != "p":
        print("Invalid input. Try again.")
        print()
        continue
    else:

        if user == "r":
            userchoice = "rock"

            rock()
            print()

            print(name,"picks Rock!")
        if user == "p":
           userchoice = "paper"

           paper()
           print()
           print(name,"picks Paper!")


        elif user == "s":
            userchoice = "scissors"

            X()
            print()
            print(name,"picks Scissors!")


        print("Now it's computers turn....")
        print('.')
        time.sleep(1)
        print('.')
        time.sleep(1)
        print('.')
        print()

        cpu = random.randint(1,3)
        if cpu == 1:
            cpuchoice = "rock"
            rock()
            print()
            print(" Computer picks rock!")

        if cpu == 2:
            cpuchoice = "paper"
            paper()
            print()
            print("Computer picks paper!")

        elif cpu ==3:
            cpuchoice = "scissors"
            X()
            print()
            print("Computer picks scissors!")


        if cpuchoice == "rock" and userchoice == "scissors" or (cpuchoice == "paper" and userchoice == "rock") or cpuchoice == "scissors" and userchoice == "paper":
            print("Computer wins this round!")
            cscore += 1
        elif cpuchoice == userchoice:
            print("Draw!")
        else:
            print(name,"Wins this round!")
            uscore +=1

        print()
        itt += 1
        print(itt)
        print(rounds)
        print(again)
        print(uscore)
        print(cscore)
        if itt == rounds and uscore == cscore:
            print("It's still a tie! Let's go one more round")
            print()
            itt -= 1
        elif cscore + uscore == rounds:




            if uscore > cscore:
                print(name,"wins!")
            else:
                print("Computer wins!")
            again = input("Play again? Enter 0 to quit.Anything else to continue")
            if again != "0":
                  rounds = input("How many rounds this time?")
                  itt = 0
                  uscore = 0
                  cscore = 0
                  again = True

            else:
                again = False

Aucun commentaire:

Enregistrer un commentaire