In ex7, I was asked to print “Cheese Burger” by defining 12 different variables.
The code is like this:
end1 = "C" end2 = "h" end3 = "e" end4 = "e" end5 = "s" end6 = "e" end7 = "B" end8 = "u" end9 = "r" end10 = "g" end11 = "e" end12 = "r"
print(end1 + end2 + end3 + end4 + end5 + end6, end = " ")
print(end7 + end8 + end9 + end10 + end11 + end12)
And the output is “Cheese Burger”.
Then I want to print 10 "Cheese ", which is inspired by this line:
print("." * 10)
So I simply add a *10 behind 【end1 + end2 + end3 + end4 + end5 + end6, end = " "】like this:
print((end1 + end2 + end3 + end4 + end5 + end6, end = " ") * 10) ^
And the error occured at the “=” point.
After searching and asking friends, I found that “end” is a kind of command that uses some letters to replace the newline function. If you uses end, then in the next line, your output will share the same line with this line.
Therefore, I change my code like this:
print((end1 + end2 + end3 + end4 + end5 + end6 + " ") * 10, end = "")
And that runs perfectly like this:
Cheese Cheese Cheese Cheese Cheese Cheese Cheese Cheese Cheese Cheese Burger
It is fun to research and debug independently, but I think it is also important for biginners to understand what you are really doing. It will be better to add the explanation of “end” command in the LPTHW ex7.