sentence = ‘every good boy does fine’
This exercise asks to ‘Store each word in a separate variable, then print out the sentence on one line using print.’ After pondering for two hours, here’s the best that I could come up with–
2 a = 'every'
3 b = 'good'
4 c = 'boy'
5 d = 'does'
6 e = 'fine'
7
8 together = a + b + c + d + e
9 print(together)
Is there an easier way to do this? Like
sentence = 'every good boy does fine'.split()
…then every item on that list is placed in its own variable; then from there, add all the variables together to piece back any sentence in a prescribed way(example–bcdae, or ecabd, etc.).
thanks for helping this noob!
Lists and other sequences can be unpacked like so:
If you add a
*before the last variable (e.g.*e) then remaining elements that don’t get unpacked can be accessed in the last variable as a list.You could then print however you want: