Python 错误消息-不支持的操作数类型

Python 错误消息-不支持的操作数类型,python,matplotlib,Python,Matplotlib,我现在更新了我的问题。我的代码中唯一没有运行的部分是值。我不断收到错误消息“Traceback(最近一次呼叫last): 文件“/Users/Documents/Circle.py”,第11行,在 xvalues.append((r*math.cos)*(math.tan*(1/n))) TypeError:不支持*:“int”和“内置函数”或“方法”的操作数类型 有人知道为什么会这样吗 import matplotlib.pyplot as plt import math xvalues =

我现在更新了我的问题。我的代码中唯一没有运行的部分是值。我不断收到错误消息“Traceback(最近一次呼叫last): 文件“/Users/Documents/Circle.py”,第11行,在 xvalues.append((r*math.cos)*(math.tan*(1/n))) TypeError:不支持*:“int”和“内置函数”或“方法”的操作数类型 有人知道为什么会这样吗

import matplotlib.pyplot as plt
import math

xvalues = []
yvalues = []

n = 6
r = 4

for r in range (0, n+1):
    xvalues.append((r * math.cos) * (math.tan * (1/n)))
    yvalues.append((r * math.sin) * (math.tan * (1/n)))


print(xvalues)
print(yvalues)

fig, ax=plt.subplots()
ax.set_title(f'''Approx. with {n} points''', fontsize=24)
ax.set_xlabel("x", fontsize=14)
ax.set_ylabel("y", fontsize=14)

plt.style.use('seaborn')

ax.plot(xvalues, yvalues, linewidth=3)

plt.show()

或者您的问题来自缺少括号:

for r in range (0, n+1):
    xvalues.append(r * math.cos (math.tan * 1/n)
    yvalues.append(r * math.sin (math.tan * 1/n)
纠正:

for r in range (0, n+1):
    xvalues.append(r * math.cos (math.tan * 1/n)) 
    yvalues.append(r * math.sin (math.tan * 1/n)) 
或/和来自空间:

fig ax = plt.subplots()
ax.set title(f"Approx. with {n} points", fontsize=24)
ax.set xlabel("x", fontsize=14)
ax.set ylabel("y", fontsize=14)
替换为:

ax = plt.subplots()
ax.set_title(f"Approx. with {n} points", fontsize=24)
ax.set_xlabel("x", fontsize=14)
ax.set_ylabel("y", fontsize=14)

数一数你的括号,请看,我把它修好了!谢谢,但我仍然在“ax”中的a上收到一条错误消息,并将fig ax=plt.subplot()替换为ax=plt.subplot(),我原以为我需要一个逗号,但现在我收到一条错误消息,在xvalues.append(r*math.cos(math.tan*1/n))中的第11行显示“Traceback(最近一次调用):File”/Users/Documents/Circle.py”TypeError:xvalues.append(r*math.cos(math.tan*1/n))中第11行的“Traceback(最近一次调用):File”/Users/Documents/Circle.py”错误信息显示,*:“builtin\u function\u或\u method”和“int”的操作数类型不受支持–您是否试图计算r*cos(tan(1/n))?