title: Can't get code in shell to work as a program
body: <p>I am working through the &quot;<a href="https://automatetheboringstuff.com" rel="nofollow noreferrer">Automate the Boring Stuff with Python</a>&quot; book and am stuck on one of the practice problems. My solution works in the shell, but not when I try to run it as a program. Here is the problem prompt:</p>
  <blockquote>
  <p>Say you have a list value like this:</p>
  <pre><code>spam = ['apples', 'bananas', 'tofu', 'cats']
  </code></pre>
  <p>Write a function that takes a list value as an argument and returns a string  with all the items separated by a comma and a space, with and inserted before the last item. For example, passing the previous spam list to the function would return 'apples, bananas, tofu, and cats'. But your function should be able to work with any list value passed to it.</p>
  </blockquote>
  <p>Here is my code:</p>
  <pre><code>def listToString(usersList):
      myStr = ', '.join(str(i) for i in usersList[0:-1]) # converts all but last list element to string and joins with commas
      myStr = myStr + ' and ' + str(usersList[-1]) # adds on &quot;and&quot;, converts  final list element to string and adds to myStr
      print(myStr)
  
  myList = input()
  listToString(myList)
  </code></pre>
  <p>When I define a list in the shell and run the above steps on it, I get the result I want:</p>
  <pre><code>'apples, bananas, tofu and cats' 
  </code></pre>
  <p>But when I try to group the steps together in the above program, the result is this:</p>
  <pre><code>[, a, p, p, l, e, s, ,,  , b, a, n, a, n, a, s, ,,  , t, o, f, u, ,,  , c, a, t, s and ]
  </code></pre>
  <p>Any ideas?</p>
  <p>Thanks very much if you've taken the time to read this. There are a couple other topics on this same practice question on SO already (<a href="https://stackoverflow.com/questions/33768758/assigning-any-list-in-a-list-to-string-script">here</a> and <a href="https://stackoverflow.com/questions/38824634/automate-the-boring-stuff-with-python-comma-code">here</a>), but I was still stuck so I went ahead and posted.</p>