作者skycat2216 (skycat2216)
看板Python
标题[问题] 新手,不晓得哪里出错
时间Tue Jun 29 15:58:20 2021
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])
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.137.234.47 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1624953503.A.D77.html
1F:→ chickengod: 第二个 while 几时结束?06/29 16:34
2F:推 lycantrope: 第二个while不会停06/29 16:49
3F:推 aalexx: 看叙述,你应该没有太多程式或解题经验,要不要先话时间补06/30 01:12
4F:→ aalexx: 一下基本CS知识?06/30 01:12
5F:→ wang0424: while要修改06/30 14:10
※ 编辑: skycat2216 (114.137.5.149 台湾), 06/30/2021 16:28:47