Python - NameError 名称 [变量] 未定义

Python - NameError name [variable] is not defined

上下文的原始问题:


我正在开发一个快速的小密码程序并遇到错误: NameError 名称 'confirm' 未定义。 我正在使用 Python 3.3,我正在尝试使用密码然后输入 no (2) 然后它会向我提供错误。 这是我的代码:

password=input ("Enter a password: ")
print ('Are you sure ' +password+ ' is a safe password?')
print ("1. YES")
print ("2. NO")
confirm=input ("Insert a number: ")

if comfirm is 2:
  password=input ("Enter a password: ")
  print ('Are you sure ' +password+ ' is a safe password?')
  print ("1. YES")
  print ("2. NO")
  confirm=input ("Insert a number: ")

  if confirm is 2:
    password=input ("Enter a password: ")
    print ('Are you sure ' +password+ ' is a safe password?')
    print ("1. YES")
    print ("2. NO")
    confirm=input ("Insert a number: ")

编辑,几年后:

请确保您始终检查您的代码是否存在拼写和语法错误,尤其是在您刚刚 deployed/built/executed 的新代码行中。错误的范围从拼写错误到不正确的大小写或语法等等。

只是打字错误-如果comfirm是2: