|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import warnings
def make(x,y):
warnings.filterwarnings("ignore")
plt.figure(figsize=(10,5))
plt.plot(x,y)
plt.title('电量统计图')
plt.xlabel('Year')
plt.ylabel('亿千瓦时')
plt.show()
def list1():
add = eval(input("请输入要添加的数据(格式一个年份一个发电量以字典的形式输入):"))
add = list(add.items())
add.sort(key = lambda x:x[0],reverse=False)
return add
a = input('添加数据(输入True),查数据(输入False):')
b = input("湖南省的数据(输入湖南省)还是全国的(输入全国)")
y1 = [62758.2,67914.2,71422.1,74170.4,81121.8]
x1 = [2017,2018,2019,2020,2021]
y2 = [1349.2,1418.8,1505.5,1496.2,1658.6]
x2 = [2017,2018,2019,2020,2021]
if a == True and b == "全国":
list1 = list1()
for x,y in list1:
y1.append(y)
x1.append(x)
while True:
del x1[0]
del y1[0]
if len(x1) == 5:
break
make(x1,y1)
if a == True and b == "湖南省":
list1 = list1()
for x,y in list1:
y2.append(y)
x2.append(x)
while True:
del x2[0]
del y2[0]
if len(x2) == 5:
break
make(x2,y2)
if a == False and b == "全国":
make(x1,y1)
if a == False and b == "湖南省":
make(x2,y2)
你第一个 input 返回的是 “True” 字符串,而不是 True 布尔值
所以你应该在后续的 if a == True 或 if a == False 都改成 if a =="True" / if a == "False"
参考代码:import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import warnings
def make(x, y):
warnings.filterwarnings("ignore")
plt.figure(figsize=(10, 5))
plt.plot(x, y)
plt.title('电量统计图')
plt.xlabel('Year')
plt.ylabel('亿千瓦时')
plt.show()
def list1():
add = eval(input("请输入要添加的数据(格式一个年份一个发电量以字典的形式输入):"))
add = list(add.items())
add.sort(key=lambda x: x[0], reverse=False)
return add
a = input('添加数据(输入True),查数据(输入False):')
b = input("湖南省的数据(输入湖南省)还是全国的(输入全国)")
y1 = [62758.2, 67914.2, 71422.1, 74170.4, 81121.8]
x1 = [2017, 2018, 2019, 2020, 2021]
y2 = [1349.2, 1418.8, 1505.5, 1496.2, 1658.6]
x2 = [2017, 2018, 2019, 2020, 2021]
if a == "True" and b == "全国":
list1 = list1()
for x, y in list1:
y1.append(y)
x1.append(x)
while True:
del x1[0]
del y1[0]
if len(x1) == 5:
break
make(x1, y1)
if a == "True" and b == "湖南省":
list1 = list1()
for x, y in list1:
y2.append(y)
x2.append(x)
while True:
del x2[0]
del y2[0]
if len(x2) == 5:
break
make(x2, y2)
if a == "False" and b == "全国":
make(x1, y1)
if a == "False" and b == "湖南省":
make(x2, y2)
|
|