-3

基本的东西,我收到了一个语法错误。如何在打印行的末尾添加句点?

first_name = raw_input("Enter your first name: ")
last_name = raw_input("Enter your last name: ")
print "Enter your date of birth" 
month= raw_input("Month? ")
day= raw_input("Day? ")
year= raw_input("Year? ")

print "Here's your information"
print first_name, "was born on", month, day+',', year.
4

2 回答 2

4

您需要将其连接起来:

print first_name, "was born on", month, day+',', year, "."

更新:正如@sr2222 指出的那样,这将在句点之前打印一个额外的空间。如果你想避免它(并假设那一年是一个字符串):

print first_name, "was born on", month, day+',', year + "."
于 2013-01-16T22:22:52.707 回答
1

在它周围加上引号。

print first_name, "was born on", month, day+',', year +'.'

虽然真的,你应该清理它,因为在一行中组合一堆不同的字符串连接机制很难阅读。

print first_name + " was born on " + month + ", " + day + ", " + year + "."

当然,还有字符串格式化的广阔天地

于 2013-01-16T22:22:38.967 回答