我试图编写一个简单的程序:
import random
x = raw_input("How many rounds:")
rounds = 0
while rounds < x:
# rock=0, paper=1, scissors=2
computer1 = random.randint(0,2)
computer2 = random.randint(0,2)
if computer1 == computer2:
print "draw"
elif computer1 == 0 and computer2 == 1:
print "lose"
elif computer1 == 1 and computer2 == 2:
print "lose"
elif computer1 == 2 and computer2 == 0:
print "lose"
else:
print "win"
rounds = rounds + 1
Run Code Online (Sandbox Code Playgroud)
为什么这会给我一个无限循环?当我取出输入行并将x替换为某个值(例如10)时,输出会给出10个结果.但为什么我不能用raw_input做呢?