输入语句响应出现语法错误

时间:2019-09-16 18:25:12

标签: python datetime syntax-error reminders

每当我尝试在代码中为三个输入语句提供输入时,都会出现错误。

我尝试在没有任何其他代码的情况下运行输入语句,并且它们运行良好。只有当我将它们包含在此代码中时,它们才会中断。

# This code is a reminder/alert system.
# This code imports the datetime functions required to allow the program to detect if there is an event.
import datetime
from datetime import date
today = date.today()
# Textual month, day and year   
d2 = today.strftime("%B %d, %Y")
# Time module import.
from datetime import datetime
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
from datetime import datetime, timedelta

# This code gets user input for an event and the day it happens.
eventName = input("What is the event name? ")
eventDate = input("What date is the event? Use the textual month/day/year (September 2, 2019). ")
eventTime = input("What time is the event? Use numeric millitary time H/M/S (14:52:30) ")

# This code defines the getRemind function that will tell the user if they do or do not have an alert for the day and/or time.
def getRemind(event, date, time):
    if d2 in eventDate: 
        return("Reminder: " + eventName + " today!")
    NACharlotte = datetime.now() + timedelta(hours=-4)
    if NACharlotte in evenTime:
        return("Reminder: " + eventName + " at " + eventTime + "!")
    if d2 in eventDate and NACharlotte in eventTime:
        return("Reminder: " + eventName + " today at " + eventTime + "!")
    print("You do not have any events today.")

# This code will print the results of the getRemind function.
print(getRemind(eventName, eventDate, eventTime))

预期结果是用户应该能够为所有三个输入语句输入数据。实际结果是以下两件事之一:如果输入了两个单词的语句(例如Bus home或Project演示文稿),则会返回“ SyntaxError:解析时出现意外的EOF”。如果使用单字输入,则返回NameError,表示未定义输入。

1 个答案:

答案 0 :(得分:0)

您在第24行的代码中有错别字:evenTime不存在。您的意思是eventTime

进行更改后,代码对我来说很好用。