简体   繁体   中英

how to increment a value using while loop python

could you tell me why my program doesnt increment "bot_points = 0" "your_points = 0" to stop the while loop when some of these values reach 3

import random
rock_paper_scissors = ["ROCK", "PAPER", "SCISSORS"]


bot_points = 0
your_points = 0
while bot_points <= 3 or your_points <= 3:
    user_choice = input('type "rock", "paper" or "scissors":  ').upper()
    bot_choice = random.choice(rock_paper_scissors)
    if bot_choice == "ROCK" and user_choice == "ROCK":
        print("Draw")
    elif bot_choice == "ROCK" and user_choice == "PAPER":
        print("You win")
        your_points = your_points+1
    elif bot_choice == "PAPER" and user_choice == "PAPER":
        print("Draw")
    elif bot_choice == "PAPER" and user_choice == "SCISSORS":
        print("You win")
        your_points= your_points+1
    elif bot_choice == "PAPER" and user_choice == "ROCK":
        print("You lose")
        bot_points = bot_points+1
    elif bot_choice == "SCISSORS" and user_choice == "PAPER":
        print("You lose")
        bot_points = bot_points+1
    elif bot_choice == "SCISSORS" and user_choice == "ROCK":
        print("You win")
        your_points = your_points+1
    elif bot_choice == "SCISSORS" and user_choice == "SCISSORS":
        print("Draw")
    elif bot_choice == "ROCK" and user_choice == "SCISSORS":
        print("You lose")
        bot_points = bot_points+1

Two issues:

  1. You test for <= 3 , so it won't end until someone wins four times
  2. You test bot_points <= 3 or your_points <= 3 , so it won't end until both players win at least four times; and would end when either reaches the threshold

If you want to end when either player wins three times, change the test to:

while bot_points < 3 and your_points < 3:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM