python - 我收到 NameError:而且我是 Python 新手
问题描述
flag = True
principleAmount = float(input("Please enter a principal amount: "))
while(flag):
userInput = str(input("(s)imple or (c)ompound interest? "))
if userInput in ['s', 'S']:
print("hello")
elif userInput in ['c', 'C']:
print("goodbye")
else:
print("wrong!")
出于某种原因,这是我得到的错误:文件“”,第 1 行,在 NameError:name 's' is not defined 这与 c 相同。我试图用你好、再见和错误来测试它,但不幸的是它不起作用
解决方案
您的代码工作正常,除了 while 循环永远运行。
推荐阅读
- angular - 如何在角度材质中动态生成可拖动组件
- python - Django:sqlite3 找不到 sqlite 文件的路径
- docker - 连接到多个网络 - 一个现有的
- laravel - 如何在两个 laravel 项目中使用相同的会话?
- sql-server - 连接表上的 SQL Server 死锁
- java - 为什么在应用 Fe 复合材料时绘图会下降?如何在 SVG 中实现多个 -feComposite 操作?
- typescript - go-ethereum 和 ethereumjs.utils 的不同签名结果
- java - 使用 Kafka Streams 处理复杂的 Avro 消息
- python - 使用 python SMTP/IMAP 在多个用户之间创建电子邮件对话
- elasticsearch - 无法识别 ElasticSearch 更新/禁用文档版本控制