简体   繁体   English

Python... 将列表中的元素相乘

[英]Python... Multiplying elements in a list

I don't understand why this is wrong.我不明白为什么这是错误的。 It's frustrating and I am losing my patience... I have deadline to finish the module and do the project by Sunday but I work full-time and I have a family to tend to.这很令人沮丧,我正在失去耐心......我必须在周日之前完成模块并完成项目,但我全职工作并且我有一个家庭需要照顾。 I have been busting my ass in my spare time to figure out why this code doesn't work and it baffles me because I haven't been able to figure it out... I run it in IDLE and it works just fine, but whenever I run it in codio I get an error "Program Failed for Input: 1,2,3,4,5,6 2 7 Expected Output: [1, 2, 3, 4, 5, 6] Your Program Output: [1, 2, 6, 4, 5, 70]我一直在业余时间拼命想弄清楚为什么这段代码不起作用,这让我感到困惑,因为我一直无法弄清楚……我在 IDLE 中运行它,它工作得很好,但是每当我在 codio 中运行它时,我都会收到错误消息“程序输入失败:1,2,3,4,5,6 2 7 预期输出:[1, 2, 3, 4, 5, 6] 您的程序输出:[ 1, 2, 6, 4, 5, 70]

Your output was incorrect.您的输出不正确。 Try again."再试一次。”

# Get our input from the command line
import sys
M= int(sys.argv[2])
N= int(sys.argv[3])

# convert strings to integers
numbers= sys.argv[1].split(',')
for i in range(0, len(numbers)):
  numbers[i]= int(numbers[i])

#I left these comments in so I can remember what values are being plugged in
#print(M) - 5
#print(N) - 3
#print(numbers)
#list2=[1,2,value1,4,5,value2]

for num in numbers:
  if(num == 3):
    #print(M*3)
    value1=(M*3)
    numbers.remove(3)
    numbers.append(value1)
  if(num == 6):
    value2=(N*10)
    numbers.remove(6)
    numbers.append(value2)
    #print(N*10)

mylist=(numbers)
order=[0,1,4,2,3,5]
mylist = [mylist[i] for i in order]
print(mylist)
# Get our input from the command line
import sys
M= int(sys.argv[2])
N= int(sys.argv[3])

# convert strings to integers
numbers= sys.argv[1].split(',')
for i in range(0, len(numbers)):
  numbers[i]= int(numbers[i])

# Your code goes here
step = N - 1
while (step<len(numbers)):
  numbers[step] *= M
  step += N
print(numbers)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM