python怎么输入和输出年月日

39次阅读
没有评论

共计 449 个字符,预计需要花费 2 分钟才能阅读完成。

在 Python 中,可以使用 input() 函数来接收用户的输入,使用 print() 函数来输出结果。

要输入年、月、日,可以分别使用 input() 函数来接收用户输入的年、月、日,并将它们存储在相应的变量中。例如:

year = int(input(" 请输入年份:"))
month = int(input(" 请输入月份:"))
day = int(input(" 请输入日期:"))

要输出年、月、日,可以使用 print() 函数来输出相应的结果。例如:

print(" 年:", year)
print(" 月:", month)
print(" 日:", day)

完整的示例代码如下:

year = int(input(" 请输入年份:"))
month = int(input(" 请输入月份:"))
day = int(input(" 请输入日期:"))

print(" 年:", year)
print(" 月:", month)
print(" 日:", day)

运行程序后,会依次提示用户输入年份、月份和日期,并在输入完成后输出相应的结果。

丸趣 TV 网 – 提供最优质的资源集合!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-12-13发表,共计449字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)