-3

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)
  • What exactly is the code supposed to do? – khelwood Sep 25 '20 at 07:54
  • 1
    I am sorry but your life stuff does not make it helps you to solve the question. What is the code even do? – Minh-Long Luu Sep 25 '20 at 07:55
  • I won't even read it all but can tell you one of your problems is you iterate over a list and while doing that you remove and append elements to it. You can't do that. – Tom Wojcik Sep 25 '20 at 07:55
  • Why can't I remove and append elements from the list? – MF Snake Sep 25 '20 at 07:56
  • So M, N, pass inputs into the code and the numbers list is the list I am editing. – MF Snake Sep 25 '20 at 07:58
  • 'You should multiply every Nth element (do not multiply the 0th element) by M. So, if N is 3, you start with the 3rd element, which is index 2. If there are less than N elements then you should output the unchanged input list.' – MF Snake Sep 25 '20 at 07:58
  • @MFSnake you should not append to the same list you iterate over. Just create a new one. – Tom Wojcik Sep 25 '20 at 07:59
  • I don't know what I am doing anymore. I run this code in IDLE Python and it outputs the list as it should. Should I do a blank list and put the value1 and value2 in? – MF Snake Sep 25 '20 at 08:04
  • Dude, if you are 'busting your a**' over this trivial bit of code, just think what's it going to be like finishing a whole module and a project! As others said, don't change the list you are iterating over. It's simple and logical. – Mario Camilleri Sep 25 '20 at 08:08
  • I have been making time in my daily life to try to understand why I can't accomplish this module using the methods I have created... It's really upsetting me because I want to learn Python so bad and understand why the language functions the way it does but the pacing for me is off... I've been reading thinkpython and utilizing linuxmint terminal to write my own codes... It is so dissapointing to me when I have to go to youtube just so I can get the right answer so I am not left behind in the class.. – MF Snake Sep 25 '20 at 08:15
  • Thanks for the encouragement though. I'll try harder. – MF Snake Sep 25 '20 at 08:16

1 Answers1

0
# 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)