[英]How can I make this function print the string in multiple lines (one word in each line) based on the number I specify?
This is my code, I want the output to be printed down in multiple lines not just one.这是我的代码,我希望将 output 打印成多行,而不仅仅是一行。
def words(name, num):
for i in range(num):
print(name)
print("content-type: text/html\n")
words("Max", 2)
The output is: output 是:
Max Max
I want我想
Max
Max
I'm running this through HTTP.我正在通过 HTTP 运行它。
You have to either wrap each word in a HTML paragraph element or put a line break after each word.您必须将每个单词包装在 HTML 段落元素中,或者在每个单词后放置一个换行符。 This is needed because browsers remove simple newlines (
\n
).这是必需的,因为浏览器会删除简单的换行符(
\n
)。 They need special HTML tags for a line break.他们需要特殊的 HTML 标签来换行。 In a pragraph:
在一段中:
def words(name, num):
for i in range(num):
print("<p>" + name "</p>")
print("content-type: text/html")
words("Max", 2)
With linebreak after the word:在单词后加上换行符:
def words(name, num):
for i in range(num):
print(name + "<br>")
print("content-type: text/html\n")
words("Max", 2)
The print
function takes an end
parameter which can be specified as: print
function 带有一个end
参数,可以指定为:
print(name, end='<br>')
Try this:尝试这个:
def words(name, num):
for i in range(num):
print(name, "\n")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.