from random import *
print("ROCK(0) \t PAPER(1) \t SCISSORS(2)")
choice = eval(input("Enter your choice: "))
count = 0
if (choice == 0):
print("You chose ROCK")
elif (choice == 1):
print("You chose PAPER")
elif (choice == 2):
print("You chose SCISSORS")
choice1 = randint(0,2)
if (choice1 == 0):
print("The computer chose ROCK")
elif (choice1 == 1):
print("The computer chose PAPER")
elif (choice1 == 2):
print("The computer chose SCISSORS")
while count <= 3 and choice == 0:
if choice1 == 0:
print("Draw")
if choice1 == 1:
print("You Lose")
if choice1 == 2:
print("You Win")
count += 1
print("ROCK(0) \t PAPER(1) \t SCISSORS(2)")
choice = eval(input("Enter your choice: "))
while count <= 3 and choice == 1:
if choice1 == 0:
print("You Win")
if choice1 == 1:
print("Draw")
if choice1 == 2:
print("You Lose")
count += 1
print("ROCK(0) \t PAPER(1) \t SCISSORS(2)")
choice = eval(input("Enter your choice: "))
while count <= 3 and choice == 2:
if choice1 == 0:
print("You Lose")
if choice1 == 1:
print("You Win")
if choice1 == 2:
print("Draw")
count += 1
print("ROCK(0) \t PAPER(1) \t SCISSORS(2)")
choice = eval(input("Enter your choice: "))
我希望这个程序循环3次,但不是这样,请你帮忙。我已经添加了所有需要的循环内容,我尝试移动代码和所有内容,它仍然无法工作,所以你可以帮助
答案 0 :(得分:0)
这样的事情?
from random import *
REPEAT = 3
count = 0
for _ in range(REPEAT):
print("ROCK(0) \t PAPER(1) \t SCISSORS(2)")
choice = eval(input("Enter your choice: "))
if (choice == 0):
print("You chose ROCK")
elif (choice == 1):
print("You chose PAPER")
elif (choice == 2):
print("You chose SCISSORS")
choice1 = randint(0,2)
if (choice1 == 0):
print("The computer chose ROCK")
elif (choice1 == 1):
print("The computer chose PAPER")
elif (choice1 == 2):
print("The computer chose SCISSORS")
if choice1 == 0:
print("this round: Draw")
elif choice1 == 1:
print("this round: You Lose")
elif choice1 == 2:
print("this round: You Win")
count += 1
if count == 0:
print("game: You Lose")
elif count == 2:
print("game: You Win")
elif count == 1:
print("game: Draw")