python代码问题
def main():sum_yao = 0
time =0
T, M = map(int, input().split())
list_yao =[]
#输入各个草药位置
for i in range(M):
list_yao.append(list(map(int, input().split())))
if list_yao[-1]>T:
list_yao[-1] =
elif list_yao[-1]!=0:
a=float(list_yao[-1]/list_yao[-1])
list_yao[-1].append(a)
print(list_yao[-1])
#给各个草药按照性价比排序
for i in range(M-1):
for j in range(i,M-1):
temp = []
if list_yao<list_yao:
temp = list_yao
list_yao = list_yao
list_yao = temp
elif list_yao==list_yao:
if list_yao<list_yao:
temp = list_yao
list_yao = list_yao
list_yao = temp
#找出在规定时间内找最高价值的东西
for i in range(M):
if list_yao == 0:
break
elif time<=T:
time = time + list_yao
sum_yao = sum_yao + list_yao
elif time>T:
time = time - list_yao
sum_yao = sum_yao - list_yao
print(sun_yao)
if __name__ == '__main__':
main()
70 3
71 100
69 1
1 2
Traceback (most recent call last):
File "D:\python\arithmetic_qq2.py", line 42, in <module>
main()
File "D:\python\arithmetic_qq2.py", line 19, in main
if list_yao<list_yao:
IndexError: list index out of range
>>> 已解决 有没有完整题目?单看你的代码明显是越界问题 傻眼貓咪 发表于 2021-12-3 19:58
有没有完整题目?单看你的代码明显是越界问题
嗯好
页:
[1]