Edit:后来发现少了行i++
谢谢各位,不然我绝对不会发现少写这行i++
本人目前在练习Python
最近在写贪心算法相关的东西
但前半段资料输入进去后整个程式都会变得很卡,然后直接被终止
环境是Python 3.9.1 (default, Jan 8 2021, 21:18:33)
[Clang 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489
on linux)]
in TermUX 0.11.4/
Python 3.8.2 on repilt.com
作业系统是Android 10(SDK 29)
以下是程式码
def takeTwo(elem):
return elem[1]
job=[]
count=0
n=int(input("How many Gunpla U want to buy"))
i=0
x=True
while(x):
temp=[]
s=input("Spec:")
e=int(input("Price:"))
v=int(input("like:"))
temp.append(i)
temp.append(s)
temp.append(e)
temp.append(v)
print(temp)
i=i+1
job.append(temp)
x=bool(input("Stop?(type anything to continue)"))
newJob=[]
l=1
k=i
i=0
while(i<k):
newTemp=[]
temp2=job[i][2]
temp3=job[i][3]
workLoad=temp3/temp2
newTemp.append(job[i][1])
newTemp.append(workLoad)
newJob.append(newTemp)
newJob.sort(key=takeTwo)
for counting in range(n):
print(newJob[counting][1],newJob[counting][2])