我只是在学习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
我的调试器给了我一个语法错误,我不知道为什么。你知道吗
基于这个问题,我假设您是第一次学习编程,因为您的问题是任何程序员必须首先学习的概念之一。你知道吗
当比较if语句中的两个内容时,需要使用
==
而不是=
。当您使用=
时,它将分配项。你知道吗另外,由于您使用的是Python,因此需要缩进if语句的主体。你知道吗
If语句(和其他控制块)需要冒号和缩进。另外,使用双精度“=”测试相等性。你知道吗
示例:
相关问题 更多 >
编程相关推荐