0

This is a repl.it problem I have been working on for the past 6 hours and as far as I can tell my code works properly from the output point of view. for example if I input 56789 my program outputs 5 7 9. Repl.it tests fail every time and tell me my output is 56789 when theirs is 5 7 9. If I define the input as a specified list instead of a user input then repl.it passes the first test and fails the second....because it indicates that the program fails with a new set of numbers. So I know stack overflow is not repl.it but not finding any help there. note...I am sure my code is clunky and inefficient but I am still learning how to walk here

def picky():
    position = 0

    a = input("") #input asking for a number  
    b = list(a)   #converts my input into a list
    c = []        #list for storing even index values
    d = []        #list for converting c to string

    while position <= len(b):
        if position % 2 == 0:
            c += b[position]
        position += 1    

    for x in c: 
        d += str(x)

    preOutput = str(d).strip('[]').replace('\'','').replace(',','')  
    # removes brackets, commas, and quotes from output.
    print(preOutput)  

picky() 

using 3.6.4

Julien
  • 13,986
  • 5
  • 29
  • 53
Seth
  • 9
  • 2
  • 1
    `' '.join(list(a)[::2])` ? – jpp Mar 20 '18 at 01:53
  • might be a version compatibility: try `str(a)` rather than `list(a)` if `a` is an int rather than a string – Julien Mar 20 '18 at 01:53
  • A good resource to better understand @jpp's suggestion: [Understanding python's slice notation](https://stackoverflow.com/questions/509211/understanding-pythons-slice-notation). – pault Mar 20 '18 at 02:07
  • 1
    Thanks for the input from everyone. I cleaned up my code above, removed some stuff that I figured out I didn't need. I was still unable to get the problem to accept my code. Reached out to my instructor who basically explained to me that Repl.it is so literal that it has limitations. He sent me some code to try and that seems to have satisfied the problem. – Seth Mar 20 '18 at 19:05

0 Answers0