【发布时间】:2018-08-22 00:36:58
【问题描述】:
我正在尝试获取要打印的课堂作业输入。
# Program Name: BadDate.py
# Function: This program determines if a date entered by the user is valid.
# Input: Interactive
# Output: Valid date is printed or user is alerted that an invalid date was entered.
validDate = True
MIN_YEAR = 0
MIN_MONTH = 1
MAX_MONTH = 12
MIN_DAY = 1
MAX_DAY = 31
month = float (input("Enter Month "))
day = float (input("Enter Day "))
year = float (input("Enter Year "))
# Get the month, then the day, then the year
# housekeeping()
# Check to be sure date is valid
if int(year) <= MIN_YEAR: # invalid year
validDate = False
elif int(month) < MIN_MONTH or int(month) > MAX_MONTH: # invalid month
validDate = False
elif int(day) < MIN_DAY or int(day) > MAX_DAY: # invalid day
validDate = False
# Test to see if date is valid and output date and whether it is valid or not
if validDate == True:
print(str(month)+'/'+str(day)+'/'+str(year) " is a valid date")
else:
print(str(month)+'/'+str(day)+'/'+str(year) " is an invalid date")
# endOfJob()
当它到达日期时,它给了我一个语法错误。我需要这些语句来打印用户输入的日期。谢谢你。
【问题讨论】:
-
您在
str(year)和" is a ...date"之间缺少+符号。应该是str(year) + " is a ...date"。
标签: python-3.x input printing