我想弄清楚如何跟踪用户输入的列表中数字的频率。我的意思是:假设有人输入 45 两次,52 次输入 52 次,22 次输入,代码会打印出类似“频率:45-2、52-3 和 22-1”的内容。提出这个问题的其他代码是针对已经在代码中创建的列表,但这个不同,因为用户正在添加到列表中。
import sys
print ("After inputting this data, the sum, average, maximum and minimum
number will be printed")
temperatureList = list()
weather=int(input("Enter the amount of days that you are looking at for
the weather:"))
print("Enter the high temperature for those next days: ")
for i in range(int(weather)):
k=int(input(""))
temperatureList.append(int(k))
sm=sum(temperatureList)
avg=sm/weather
print("SUM = ",sm)
print("AVERAGE = ",avg)
temperatureList.sort()
print("This is the numbers from low to high", temperatureList)
print("Maximum number in the list is:", max(temperatureList), "and the
minimum number is: ", min(temperatureList))
while True:
action = int(input("Input add if you want to add to the list again. Or
remove if you want to remove from the list, or end if you want to end this
program"))
if action == add:
print("Enter what you want to be added ")
add = int(input(""))
temperatureList.append(add)
print(temperatureList)
sm = sum(temperatureList)
avg = sm / weather
print("SUM = ", sm)
print("AVERAGE = ", avg)
temperatureList.sort()
print("This is the numbers from low to high", temperatureList)
elif action == remove:
if len(temperatureList) > 1:
del temperatureList[-1]
print(temperatureList)
sm = sum(temperatureList)
avg = sm / weather
print("SUM = ", sm)
print("AVERAGE = ", avg)
else:
print("Everything removed from the list")
elif action == end:
sys.exit()
拉风的咖菲猫
catspeake
相关分类