如何解决菜单不重复:一旦我查看了以后的功能,菜单就不会让我去早期的项目
下面是我的代码。这里还有一个指向我的 repl 的链接: https://repl.it/@AZZ1/Feb-test#main.py
一旦我查看了较晚的功能,菜单就不会让我进入较早的项目。有什么办法可以解决吗?
import matplotlib.pyplot as plt
# # # # # # Part 1
day_one_temp = [4.5,4.2,4,3.2,2.5,1.9,2.8,3,2.3,1.7,2,3.6,4.5,5,5.7,5.4,5.1,4.3,3.1,1.5,1.2]
day_two_temp = [1.1,0.6,0.1,0.3,0.4,0.8,1.3,1.4,2.6,2.2,2.1,0.7,-0.3,-0.6,-1.1,-1.2,-1.5]
day_three_temp = [-1.4,-1.4,-1.3,-1.5,-1.6,-0.4,2.4,3.9,4.4,4.5]
###Variables I created
Time = ['1:00','2:00','3:00','4:00','5:00','6:00','7:00','8:00','9:00','10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00','24:00']
Days = ['29.12.2020','30.12.2020','31.12.2020']
#graph 1 Q1
def graph1Question1Part1():
print('This function shows the temperature of day one')
plt.plot(Time,day_one_temp,'b:')
plt.title('Graph of day one temperature')
plt.ylabel('Temperature of that hour')
plt.xlabel('Time of the day')
plt.ylim(-3,7)
plt.grid()
plt.savefig('Part1Q1Graph1,DayOneTemp.png')
plt.show()
#graph2 Q1
def graph2Question1Part1():
print('This function shows the temperature of day two')
plt.plot(Time,day_two_temp,'b:')
plt.title('Graph of day two temperature')
plt.ylabel('Temperature of that hour')
plt.xlabel('Time of the day')
plt.ylim(-3,7)
plt.grid()
plt.savefig('Part1Q1Graph2,dayTwoTemp.png')
plt.show()
# graph 3 Q1
def graph3Question1Part1():
print('This function shows the temperature of day three')
plt.plot(Time,day_three_temp,'b:')
plt.title('Graph of day three temperature')
plt.ylabel('Temperature of that hour')
plt.xlabel('Time of the day')
plt.ylim(-3,7)
plt.grid()
plt.savefig('Part1Q1Graph3,DayThreeTemp.png')
plt.show()
# graph Q2
def Question2Part1():
print('This function shows the temperature of all days')
plt.plot(Time,'y--')
plt.plot(Time,'r-.')
plt.plot(Time,'b-')
plt.legend(['Dayone','Daytwo','Daythree'])
plt.title('Graph of day one,two,three temperature')
plt.ylabel('Temperature of that hour')
plt.xlabel('Time of the day')
plt.ylim(-3,7)
plt.grid()
plt.savefig('Part1Q2,AllDaystemperature.png')
plt.show()
#graph Q3
def Question3Part1():
print('This function shows the temperature of all days ')
Average1 = sum(day_one_temp)/len(day_one_temp)
Average1Rounded = round(Average1,1)
Average2 = sum(day_two_temp)/len(day_two_temp)
Average2Rounded = round(Average2,1)
Average3 = sum(day_three_temp)/len(day_three_temp)
Average3Rounded = round(Average3,1)
AverageTemperature = [Average1Rounded,Average2Rounded,Average3Rounded]
plt.bar(Days,AverageTemperature,width = 0.6)
plt.title('Average temperature')
plt.xlabel('Date')
plt.ylabel('Temperature')
plt.grid()
plt.savefig('Part1Q3.AverageTemperatureBarchart.png')
plt.show()
# graph1 Q4
def Question4Part1():
print('This function shows the minimum and maximum temperature of all days')
Minday1 = min(day_one_temp)
Minday2 = min(day_two_temp)
Minday3 = min(day_three_temp)
Maxday1 = max(day_one_temp)
Maxday2 = max(day_two_temp)
Maxday3 = max(day_three_temp)
plt.bar(Days,[Maxday1-Minday1,Maxday2-Minday2,Maxday3-Minday3],color = ['red','blue','green'],bottom = [Minday1,Minday2,Minday3])
plt.grid()
plt.title('Min/max temperatures')
plt.xlabel('Date')
plt.ylabel('Max / Min temperature range')
plt.ylim(-3,7)
plt.savefig('Part1Q4.MinMaxTempRange.png')
plt.show()
# # # # # # # #part 2
day_one_rainfall = [0,0.2,1.1,3.4,0.5,0]
day_two_rainfall = [0,0.9,0]
day_three_rainfall = [0.3,0.8]
# Graph 1 Q2
def graph1Question1Part2():
print('This function shows the rainfall for day one')
plt.plot(Time,day_one_rainfall,'y--')
plt.title('Graph of day one rainfall')
plt.xlabel('Time of the day')
plt.ylabel('Amount of rainfall')
plt.ylim(-1,5)
plt.savefig('Part2Q1Graph1.DayOneRainfall.png')
plt.show()
#graph2 Q2
def graph2Question1Part2():
print('This function shows the rainfall for day two')
plt.plot(Time,day_two_rainfall,'r-.')
plt.title('Graph of day two rainfall')
plt.xlabel('Time of the day')
plt.ylabel('Amount of rainfall')
plt.grid()
plt.ylim(-1,5)
plt.savefig('Part2Q1Graph2.DayTwoRainfall.png')
plt.show()
#graph 3 Q2
def graph3Question1Part2():
print('This function shows the rainfall for day three')
plt.plot(Time,day_three_rainfall,'g--')
plt.title('Graph of day three rainfall')
plt.xlabel('Time of the day')
plt.ylabel('Amount of rainfall')
plt.grid()
plt.ylim(-1,5)
plt.savefig('Part2Q1Graph3.DayThreeRainfall.png')
plt.show()
# graph 4 Q2
def Question2Part2():
print('This function shows the rainfall for all days')
plt.plot(Time,'y-')
plt.plot(Time,'r-')
plt.plot(Time,'g-')
plt.legend(['Day one rainfall','Day two rainfall','Day three rainfall'])
plt.title('All days rainfall')
plt.xlabel('Time of the day')
plt.ylabel('Amount of rainfall')
plt.grid()
plt.ylim(-1,5)
plt.savefig('Part2Q2.AllDaysRainfall.png')
plt.show()
#graph 5 Q2
def Question3Part2():
print('This function shows the total rainfall for each day')
SumOfDayOne = sum(day_one_rainfall)
SumOfDayTwo = sum(day_two_rainfall)
SumOfDayThree = sum(day_three_rainfall)
plt.bar(Days,[SumOfDayOne,SumOfDayTwo,SumOfDayThree],width = 0.4)
plt.title('Total rainfall of each day')
plt.xlabel('Date')
plt.ylabel('Amount of rainfall')
plt.grid()
plt.ylim(-1,12)
plt.savefig('Part2Q3.TotalRainfallOfEachDayBarChart.png')
plt.show()
#graph 6 Q2
def Question4Part2():
print('This function shows the total rainfall for each day')
SumOfDayOne = sum(day_one_rainfall)
SumOfDayTwo = sum(day_two_rainfall)
SumOfDayThree = sum(day_three_rainfall)
plt.pie([SumOfDayOne,labels = Days)
plt.title('Rainfall of the three days in pie chart')
plt.savefig('Part2Q4.TotalRainfallOfEachDayPieChart.png')
plt.show()
#graph 7 Q2
def Question5Part2():
print('This function shows the total rainfall for each day')
RainFalloverThreeDays = []
for i in range(0,len(day_one_rainfall)):
RainFalloverThreeDays.append(day_one_rainfall[i] + day_two_rainfall[i]+day_three_rainfall[i])
plt.plot(Time,RainFalloverThreeDays,'b-.')
plt.title('Rain Fall Over Three Days')
plt.xlabel('Time')
plt.ylabel('Amount of rainfall')
plt.grid()
plt.ylim(-1,5)
plt.savefig('Part2Q5.RainFallOfEachHourOverThreeDays.png')
plt.show()
print('Please enter the number of the question you want to view')
print('Enter 0 to exit')
print('The Questions available are - P1Q1G1,P1Q1G2,P1Q1G3,P1Q2,P1Q3,P1Q4,P2Q1G1,P2Q1G2,P2Q1G3,P2Q2,P2Q3,P2Q4,P2Q5')
question = input('Enter your question ').upper()
if question != 0 :
if question == 'P1Q1G1':
print("Part 1 Question 1 Graph 1 is running")
graph1Question1Part1()
print('The Questions available are - P1Q1G1,P2Q5 ')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 'P1Q1G2':
print('Part 1 Question 1 Graph 2 is running')
graph2Question1Part1()
print('The Questions available are - P1Q1G1,P2Q5 ')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 'P1Q1G3':
print('Part 1 Question 1 Graph 3 is running')
graph3Question1Part1()
print('The Questions available are - P1Q1G1,P2Q5 ')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 'P1Q2':
print('Part 1 Question 2 is running')
Question2Part1()
print('The Questions available are - P1Q1G1,P2Q5')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 'P1Q3':
print('Part 1 Question 3 is running')
Question3Part1()
print('The Questions available are - P1Q1G1,P2Q5')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 'P1Q4':
print('Part 1 Question 4 is running')
Question4Part1()
print('The Questions available are - P1Q1G1,P2Q5 ')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 'P2Q1G1':
print('Part 2 Question 1 Graph 1 is running')
graph1Question1Part2()
print('The Questions available are - P1Q1G1,P2Q5 ')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 'P2Q1G2':
print('Part 2 Question 1 Graph 2 is running')
graph2Question1Part2()
print('The Questions available are - P1Q1G1,P2Q5 ')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 'P2Q1G3':
print('Part 2 Question 1 Graph 3 is running')
graph3Question1Part2()
print('The Questions available are - P1Q1G1,P2Q5 ')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 'P2Q2':
print('Part 2 Question 2 is running')
Question2Part2()
print('The Questions available are - P1Q1G1,P2Q5 ')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 'P2Q3':
print('Part 2 Question 3 is running')
Question3Part2()
print('The Questions available are - P1Q1G1,P2Q5 ')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 'P2Q4':
print('Part 2 Question 4 is running')
Question4Part2()
print('The Questions available are - P1Q1G1,P2Q5 ')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 'P2Q5':
print('Part 2 Question 5 is running')
Question5Part2()
print('The Questions available are - P1Q1G1,P2Q5 ')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question != 'P1Q1G1' and question != 'P1Q1G2' and question != 'P1Q1G3' and question != 'P1Q2' and question != 'P1Q3' and question != 'P1Q4' and question != 'P2Q1G1' and question != 'P2Q1G2' and question != 'P2Q1G3' and question != 'P2Q2' and question != 'P2Q3' and question != 'P2Q4' and question != 'P2Q5':
print('Invalid input,please enter again')
print('The Questions available are - P1Q1G1,P2Q5 ')
print('Choose 0 to exit')
question = input('Enter your question ').upper()
if question == 0:
print('Programme exited')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。