dimanche 2 juin 2019

How to get different results from a random.choice in a nested while loop

This is a rock, paper scissors program minigame, however the random.choice selects only one from the list even though it repeats the choice in a nested loop.

I've tried looking at other answers but most of them state about using a loop, the others aren't adequate enough for my case.

              rpsloop = True
              while rpsloop:
                  #credit to https://thehelloworldprogram.com/python/python-game-rock-paper-scissors/ for help
                  aiselc = ["rock","paper","scissors"]
                  computer = random.choice(aiselc)
                  print("type exit to leave")
                  player = input("rock, paper, scissors?")
                  if player == computer:
                    print("Tie!")
                    print("-------------------------")
                    continue
                  elif player == "rock":
                    if computer == "paper":
                     print("You lose!", computer, "covers", player)
                     print("-------------------------")

                     continue
                    else:
                     print("You win!", player, "smashes", computer)
                     print("-------------------------")
                     continue
                  elif player == "Paper":
                    if computer == "Scissors":
                     print("You lose!", computer, "cut", player)
                     print("-------------------------")
                     continue
                    else:
                     print("You win!", player, "covers", computer)
                     continue
                  elif player == "Scissors":
                    if computer == "Rock":
                     print("You lose...", computer, "smashes", player)
                     print("-------------------------")
                     continue
                    else:
                     print("You win!", player, "cut", computer)
                     print("-------------------------")
                     continue
                  else:
                       break
          else:
              break

I expect the computer to pick either rock, paper or scissors. it picks one and keeps the value even after a loop. however it picks another value each execution.




Aucun commentaire:

Enregistrer un commentaire