Exercise 7 in LPTHW book

This pertains to Exercise 7, page 56 in the LPTHW book (Python 3 version).

print(end1 + end2 + end3 + end4 + end5 + end6) gives as output Cheese

print(end7 + end8 + end9 + end10 + end11 + end12) gives as output Burger

The output for the two lines would be:
Cheese
Burger

#Now i add the end = ‘’ code snippet to the end of the first line to have:

print(end1 + end2 + end3 + end4 + end5 + end6, end=’ ')
print(end7 + end8 + end9 + end10 + end11 + end12)

The output for the above two lines would be:
Cheese Burger

So the end = ‘’ code snippet is making the output (“Cheese”) end with a space rather than a line break.

But what if I omit the second line altogether and just try to print out the first line with the additional code snippet:

print(end1 + end2 + end3 + end4 + end5 + end6, end=’ ')

It doesn’t print out anything, can someone tell me why?

Simply delete the space in your end=' '`` code, so that it's justend=’’``` and it won’t print that. The end parameter is simply anything you want, so if you put a space it writes a space.

1 Like