当我尝试输入某些东西(使用)时,运行以下代码会给我一个NameError,请提供帮助。
import matplotlib.pyplot as plt
use = eval(input("Enter activites:"))
amount = eval(input("Amount:"))
plt.pie(amount, labels = use)
plt.show()
[使用matplotlib时,请尝试使用值列表生成图。
例如,尝试以下操作:
import matplotlib.pyplot as plt
counter = 0
uses = list()
amounts = list()
while True:
counter += 1
use = input("Enter activity " + str(counter) + " (0 to finish): ")
if use == "0":
break
else:
uses.append(use)
amount = eval(input("Enter amount for " + use + ": "))
amounts.append(amount)
plt.pie(amounts, labels=uses)
plt.show()