python - 为什么在 python 中创建一个函数时出现语法错误,该函数接受两个参数来确定我将获得的超速罚单类型?
问题描述
你开得太快了,警察拦住了你。编写一个函数以返回 3 种可能结果之一:“无票”、“小票”或“大票”。如果您的速度为 60 或更低,则结果为“无票”。如果速度介于 61 和 80 之间(含),则结果为“小票”。如果速度为 81 或更高,则结果为“大票”。除非是你的生日——在你生日那天,你的速度在所有情况下都可以提高 5 倍。
这是我为解决上述问题而创建的函数(在 Jupyter Notebook 中):
def caught_speeding (speed, is_birthday):
if speed <= 60:
print ('no ticket')
elif speed >= 66 and speed <= 85 and is_birthday = 'Y':
print ('small ticket')
elif speed >= 61 and speed <= 80 and is_birthday = 'N':
print ('small ticket')
elif speed >= 86 and is_birthday = 'Y':
print ('big ticket')
elif speed >= 81 and is_birthday = 'N':
print ('big ticket')
else:
print ('null')
不幸的是,我收到了这个错误:
[
如果我只使用第一个参数创建函数,我不会收到此错误。
解决方案
尝试==
平等比较,而不是=
推荐阅读
- javascript - React - 使用 axios 更新列表并同时刷新
- r - 如何在 dplyr::semi_join() 中针对 Oracle 指定覆盖 = T
- python-3.x - 在读取 csv 时识别 pandas 中的日期列
- python - Google Datastore:迭代器已经启动 - 如何使用这些迭代器?
- c# - C# 中的 Windows 时区下拉菜单
- python - 无限滚动条不适用于 django
- javascript - 简单上传ckeditor 5 无法上传文件:未定义
- javascript - 获取 HTTP 状态 500 ?将 tomcat 7 升级到 8 时出现内部服务器错误
- asp.net-mvc - 在生产中找不到视图,在本地工作正常
- c# - 使用 Azure Log Analytics 在 Azure Function v3 中进行结构化日志记录