Python... Multiplying elements in a list

138 views Asked by At

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]

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)
1

There are 1 answers

0
MF Snake On
# 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)