奇怪的Python错误

Bil*_*ljk 0 python function

我正在制作一个python脚本,向你推荐新音乐,但由于某种原因,我遇到了很多错误.脚本没有完成,但现在是

#!/usr/bin/env python
print("This is to help you find new bands!")
pop = 0
def indie():
    global indie
    global classic_rock
    global metal
    global pop
    indie = 0
    classic_rock = 0
    metal = 0
    pop = 0
    indie += 3
    classic_rock -= 1
    metal -= 1.5
    pop -= 3
def notindie():
    global indie
    indie += 1
def classicrock():
    global classic_rock
    classic_rock += 2
def notclassicrock():
    global classic_rock
    classic_rock -= 1
def popp():
    global pop
    global indie
    pop += 3
    indie -= 3
def notpop():
    global pop
    global metal
    pop -= 1
    metal += 1
def notmetal():
    global metal
    global pop
    metal -= 3
    pop += 1
def metal():
    global metal
    global pop
    global indie
    global classicrock
    classicrock += 1
    metal += 3
    indie -= 1
    pop -= 4
que = input("Do you consider yourself to be a hipster? (Yes/No) ")
if que == 'yes':
    indie()
if que == 'no':
    notindie()
que2 = input("Do you like the Rolling Stones? (Yes/No) ")
if que2 == 'yes':
    classicrock()
if que2 == 'no':
    notclassicrock()
que3 = input("Do you like Britney Spears? (Yes/No) ")
if que3 == 'yes':
    popp()
if que3 == 'no':
    notpop()
que4 = input("Do you like Metallica? (Yes/No) ")
if que4 == 'no':
    notmetal()
if que4 == 'yes':
    metal()
Run Code Online (Sandbox Code Playgroud)

如果我输入yes你喜欢metallica,我会收到错误

File "tastepy.py", line 69, in <module>
    metal()
TypeError: 'float' object is not callable
Run Code Online (Sandbox Code Playgroud)

如果我为时髦问题输入no:

Traceback (most recent call last):
  File "tastepy.py", line 54, in <module>
    notindie()
  File "tastepy.py", line 19, in notindie
    indie += 1
TypeError: unsupported operand type(s) for +=: 'function' and 'int'
Run Code Online (Sandbox Code Playgroud)

我得到了这些虽然金属中没有漂浮物()任何人都知道发生了什么?

dka*_*ins 5

问题是你的函数使用与变量相同的名称,并且它们互相破坏.尝试使用不同的名称,例如功能likes_metal()和变量metal_score.

您还应该在全局级别声明和初始化全局变量,而不是在indie函数内.