python – NameError:名称’now’未定义
发布时间:2020-12-20 12:29:52 所属栏目:Python 来源:网络整理
导读:参见英文答案 error in python d not defined. ????????????????????????????????????3个 从这个源代码: def numVowels(string): string = string.lower() count = 0 for i in range(len(string)): if string[i] == "a" or string[i] == "e" or string[i] =
参见英文答案 >
error in python d not defined. ????????????????????????????????????3个
从这个源代码: def numVowels(string): string = string.lower() count = 0 for i in range(len(string)): if string[i] == "a" or string[i] == "e" or string[i] == "i" or string[i] == "o" or string[i] == "u": count += 1 return count print ("Enter a statement: ") strng = input() print ("The number of vowels is: " + str(numVowels(strng)) + ".") 运行时出现以下错误: Enter a statement: now Traceback (most recent call last): File "C:Usersstevengfowlerexercise.py",line 11,in <module> strng = input() File "<string>",line 1,in <module> NameError: name 'now' is not defined ================================================== 解决方法
使用
raw_input() 而不是
input() .
在Python 2中,后者尝试输入 在Python 3中,没有raw_input(); input()可以正常工作(它不是eval()). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |