Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Using .join()
#1
Hi there,

I'm supposed to join up the string by entering an input. I can't seem to get it to work, I suspect the separator i input might not be a string. Any advice?

phrase_words = ['Jack', 'and', 'Jill', 'went', 'up', 'the', 'hill', 'To', 'fetch', 'a', 'pail', 'of', 'water']

separator = input("Enter: ")

print(separator.join(phrase_words))
Thanks
Quote
#2
(Jun-26-2020, 06:40 AM)extricate Wrote: I can't seem to get it to work, I suspect the separator i input might not be a string. Any advice?

What exactly doesn't work? input returns a string, so I don't know what you mean.
Quote
#3
Weird, I put the code into visualizer and it worked.

Guess my jupyter has some problem running the code

The error code was:

Enter: -
File "<string>", line 1
&
^
SyntaxError: unexpected EOF while parsing
Quote
#4
Are you by any chance using Python 2? I suspect so, as input behaves like eval in Python 2, so it's trying to evaluate what you enter as Python code. If you are using Python 2, why? It has been end of life since the beginning of the year.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)