我知道我应该做什么,但我相信我在这里错过了一步。。。我之前从第1行得到一个语法错误
range(1, 51)
For answer in range:
if answer % 3 == 0 and answer % 5 ==0
print (“Wolly Bully”)
elseif answer % 3 == 0 and answer % 5 = <0
print (“Wolly”)
elseif answer % 3 = <0 and answer % 5 == 0
print (“Bully”)
elseif answer % 3 = <0 and answer % 5 = <0
print (str(answer) + " ", end = "")
您可以使用
range(1, 51)
定义一个范围,但是range
是一个函数,因此您需要对它返回的范围做一些处理例如:
而且,因为您不需要任何其他方面的范围,这是一个更好的解决方案:
您的代码还有一些问题,其中许多是打字错误-这里有一个更正的版本(不保证正常工作,但它可以运行):
有几种类型的更改:
elif
而不是elseif
if
或elif
后面的冒号<=
而不是= <
for
if
和elif
表达式(如果某个表达式不满足if x == y
,那么elif x <= y
就没有意义了,编写elif x < y
就更清楚了,因为这是执行代码的唯一情况考虑到大写和奇怪的引号,您可能正在使用不合适的编辑器来编写代码-强烈建议使用编程编辑器或IDE,如VSCode(免费)、PyCharm(免费社区)或许多其他(也免费)替代品
有几个错误,将
range
与for
一起使用,在Python中是elif
,大多数比较运算符需要更正(<=
而不是=>
):输出:
相关问题 更多 >
编程相关推荐