我刚开始学习用Python编程,我尝试制作一个摇滚纸剪刀游戏来训练自己。
我在使用while循环的代码末尾遇到了问题 它没有考虑我的computer_score所以如果我必须创建一个变量并添加一个参数,以完成无限循环
user_choice = "Rock"
user_score = 0
computer_score = 0
def fight(user_choice):
if user_choice == "Rock":
scissor = 1
rock = 2
paper = 3
user_choice = rock
computer_choice = randint(1, 3)
print computer_choice
if user_choice == computer_choice:
print 'DRAW!'
elif user_choice > computer_choice:
print 'User win, consciousness can\'t be beaten, you win'
global user_score
user_score += 1
elif user_choice < computer_choice:
print 'Computer win, singularity has been reach'
global computer_score
computer_score += 1
i = 0
while (computer_score < 3 or i < 30):
fight(user_choice)
i = i + 1
答案 0 :(得分:0)
可能存在randint(1,3)总是返回1的情况。因此计算机永远不会获胜。这样你的while循环就会无限延续。