定义名称时的名称错误?用于班级项目
感谢您抽出宝贵的时间阅读本文。在星期五之前,我有一个项目。该项目基本上正在分析世界上最受欢迎的歌曲。用户将输入W是他们希望在全球范围内看到最受欢迎的流派以及它拥有多少流。我的程序由两个Python文件组成,一个文件包含前10个歌曲列表,另一个包含用户输入其选项的文件。 这是我的top10songs的文件:
def Mostpopularw(Pop):
Pop =='Pop with 10,882,755,219 streams worldwide'
return Pop
文件
if choice=='W':
print(top10songs.Mostpopularw(Pop))
以及用户将输入代码运行正常的 ,但是当我尝试输入'w时;它打印出来 名称:名称“ pop”未定义 但是我不明白流行音乐的定义是如何定义的吗?谁能帮我吗? 谢谢!
Thank you for taking time to read this. I have a project due for my Programming class by Friday. The project is basically analyzing the most popular songs around the world. The user will input W is they want to see the most popular genre worldwide and how many streams it has. My program consists of two python files, one that contains the top 10 song list, and the other where the user will input their options.
Here is my file for my top10songs:
def Mostpopularw(Pop):
Pop =='Pop with 10,882,755,219 streams worldwide'
return Pop
and the file for where the user will put input
if choice=='W':
print(top10songs.Mostpopularw(Pop))
the code runs fine but when I try to enter 'W; it prints out
NameError: name 'Pop' is not defined
but I dont understand how pop is not defined? Can anyone help me?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前尚不清楚您想要
MostPopularW
函数要做什么,因此我们很难帮助您做到这一点。当前代码与常量字符串进行比较pop
参数时,并没有多大意义,然后在返回相同的pop 值。
可能是您只希望该函数到
return
字符串,在这种情况下,它不应该是一个参数:现在,调用代码不需要传递
pop的参数
,这是您遇到的错误(您传递了不存在的事物)。It is not very clear what you want your
Mostpopularw
function to do, so its hard for us to help you make it do that thing. The current code doesn't make much sense, as you're comparing aPop
argument with a constant string, and then throwing away the result of the comparison before returning the samePop
value.It may be that you just want the function to
return
the string, in which case it shouldn't be an argument:Now the calling code doesn't need to pass in an argument for
Pop
, which was the error you were having (you were passing in something that didn't exist).