定义名称时的名称错误?用于班级项目

发布于 2025-01-22 22:52:03 字数 456 浏览 3 评论 0原文

感谢您抽出宝贵的时间阅读本文。在星期五之前,我有一个项目。该项目基本上正在分析世界上最受欢迎的歌曲。用户将输入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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安人多梦 2025-01-29 22:52:03

目前尚不清楚您想要MostPopularW函数要做什么,因此我们很难帮助您做到这一点。当前代码与常量字符串进行比较pop参数时,并没有多大意义,然后在返回相同的pop 值。

可能是您只希望该函数到return字符串,在这种情况下,它不应该是一个参数:

def Mostpopularw():
    Pop = 'Pop with 10,882,755,219 streams worldwide'  # note, one = sign here!
    return Pop

现在,调用代码不需要传递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 a Pop argument with a constant string, and then throwing away the result of the comparison before returning the same Pop value.

It may be that you just want the function to return the string, in which case it shouldn't be an argument:

def Mostpopularw():
    Pop = 'Pop with 10,882,755,219 streams worldwide'  # note, one = sign here!
    return Pop

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文