If语句的语法错误

时间:2015-09-14 19:17:54

标签: python debugging

我正在学习Python,现在我正在制作一个非常简单的摇滚,纸张,剪刀游戏,用户选择一个选项,然后计算机随机选择另一个,然后程序比较两个并说明谁赢了。 我的代码如下所示:

print ('Rock, Paper, Scissors! The game of random guessing!')
print (input('Please hit enter to begin'))
choice = input('Choose Rock, Paper, or Scissors: ')
print('You decided on: ', choice)

import random
'''random gives this program the ability to randomly choose from a list'''
ComputerChoiceOptions = ['Rock', 'Paper', 'Scissors']
ComputerChoice = random.choice(ComputerChoiceOptions)
print('The computer went with:', ComputerChoice)

if choice = ComputerChoice
Winner = 'Tie'
    Print(Winner)

我的问题特别针对这一点

 if choice = ComputerChoice

我的调试器给出了一个语法错误,我不知道为什么。

2 个答案:

答案 0 :(得分:0)

如果语句(和其他控制块)需要冒号和缩进。另外,使用double'='来测试相等性。

示例:

panel.Enabled = false

答案 1 :(得分:-1)

基于这个问题我假设你是第一次学习编程,因为你的问题是程序员必须学习的第一个概念之一。

在比较if语句中的两个内容时,您需要使用==而不是=。当您使用=时,它会分配该项目。

此外,由于您使用的是Python,因此需要缩进if语句的主体。