所以我一直在努力做到這一點,這樣我就可以列印出一條長線,這樣我就可以讓它看起來很花哨,但似乎不像正常作業......
playerguess = input()
playerguess = int(playerguess)
days = 2
example = ("Looks like this storm won't stop for another ", days playerguess, " we will have to wait")
print("-Captain Strand- \"", example, "\" (You can barely hear him but thats all you hear)")
uj5u.com熱心網友回復:
對于您的示例,您可能打算使用"".join(example),但是,您可能真的想要模板化一個多行字串并使用.format()(這兩種方法都是string)
TEMPLATE = """{header}
"Looks like this storm won't stop for another {days}, we will have to wait"
(You can barely hear him but thats all you hear)"""
TEMPLATE.format(
header="-Captain Strand-",
days=days playerguess,
)
>>> print(TEMPLATE.format(
... header="-Captain Strand-",
... days=days playerguess,
... ))
-Captain Strand-
"Looks like this storm won't stop for another 5, we will have to wait"
(You can barely hear him but thats all you hear)
起初
>>> example = ("Looks like this storm won't stop for another ", days playerguess, " we will have to wait")
>>> example # example is a tuple of strings
("Looks like this storm won't stop for another ", 5, ' we will have to wait')
>>> example = "".join(("Looks like this storm won't stop for another ", str(days playerguess), " we will have to wait"))
>>> example # example is a single string
"Looks like this storm won't stop for another 5 we will have to wait"
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/453519.html
