[问题] 新手,不晓得哪里出错

楼主: skycat2216 (skycat2216)   2021-06-29 15:58:20
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])
作者: chickengod (鸡大侠)   2021-06-29 16:34:00
第二个 while 几时结束?
作者: lycantrope (阿宽)   2021-06-29 16:49:00
第二个while不会停
作者: aalexx (aalexx.S)   2021-06-30 01:12:00
看叙述,你应该没有太多程式或解题经验,要不要先话时间补一下基本CS知识?
作者: wang0424 (FFFFFF)   2021-06-30 14:10:00
while要修改

Links booklink

Contact Us: admin [ a t ] ucptt.com