[英]Why am I getting this message invalid syntax?
i write code if statement but there is a wrong in it.我编写代码 if 语句,但其中有错误。 this is the code
这是代码
mark = float(input('enter your mark : '))
if mark < 50:
result = 'failed'
elif mark >= 50 and < 75:
result = 'accepted'
elif mark >= 75 and < 85:
result = 'good'
elif mark >= 85 and < 90:
result = 'very good'
else:
result = 'excellent'
print(result)
the message appear is invalid syntax in line 4 about < assignment any help here guys?出现的消息是第 4 行中关于 < 赋值的无效语法 伙计们有什么帮助吗?
mark >= 50 and < 75
is not a valid expression, you must write mark >= 50 and mark < 75
instead. mark >= 50 and < 75
不是有效的表达式,您必须改写mark >= 50 and mark < 75
。 Alternatively, you can use a chained comparison: 50 <= mark < 75
.或者,您可以使用链式比较:
50 <= mark < 75
。
The proper syntax is either elif mark >= 50 and mark < 75:
or elif 50 <= mark < 75:
正确的语法是
elif mark >= 50 and mark < 75:
或elif 50 <= mark < 75:
This would be your code that actually runs:这将是您实际运行的代码:
mark = float(input('enter your mark : '))
if mark < 50:
result = 'failed'
elif mark >= 50 and mark < 75:
result = 'accepted'
elif mark >= 75 and mark < 85:
result = 'good'
elif mark >= 85 and mark < 90:
result = 'very good'
else:
result = 'excellent'
print(result)
As others stated mark >= 50 and < 85
is not valid in Python.正如其他人所说
mark >= 50 and < 85
在 Python 中无效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.