首页 > 解决方案 > 我收到 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 相同。我试图用你好、再见和错误来测试它,但不幸的是它不起作用

标签: pythonpython-3.x

解决方案


您的代码工作正常,除了 while 循环永远运行。


推荐阅读