该程序几乎总是返回“这是平局(或平局)”。只是我还是有什么问题?这是一个剪刀石头布程序,进行 10 轮并最终显示结果。
#!/usr/bin/python
# RockPaperScissors from Python
import random;
i = 1;
c = 0;
u = 0;
d = 0;
while i <= 10:
userAnswer = input("Do you choose rock, paper, or scissors?");
computerAnswer = random.randint(1, 3);
if (computerAnswer == 1):
computerAnswer = "rock";
elif (computerAnswer == 2):
computerAnswer = "paper";
else:
computerAnswer = "scissors";
if (computerAnswer == "rock" and userAnswer == "paper"):
print("You won(paper beats rock)");
u = u + 1;
elif (computerAnswer == "" and userAnswer == "paper"):
print("You lost(rock beats scissors)");
c = c + 1;
elif (computerAnswer == "paper" and userAnswer == "rock"):
print("You lost(paper beats rock)");
c = c + 1;
elif (computerAnswer == "paper" and userAnswer == "scissors"):
print ("You won(scissors beat paper)");
u = u + 1;
elif (computerAnswer == "scissors" and userAnswer == "paper"):
print("You lost(scissors beats paper)");
c = c + 1;
elif (computerAnswer == "scissors" and userAnswer == "rock"):
print("You won(rock beats scissors)");
u = u + 1;
else:
print("It's a draw!");
d = d + 1;
if (i == 10):
print("You won " + str(u) + " times.");
print("You lost " + str(c) + " times.")
print("It was a draw " + str(d) + " times.");
i += 1;
Python的版本是3.2(Python 3.2)