python

python怎么输入和输出年月日

小亿
624
2023-12-07 10:55:12
栏目: 编程语言

在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)

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

0
看了该问题的人还看了