-1

I have some code. When User write "Date" in input line, output must be date, like 2019-06-8 16:34:40 but program can not find input text - name 'date' is not defined

import datetime

x = input("Type your question here ... ")
########## Date ##########
now = datetime.datetime.now()
date = "Date"
if x == date:
  print "Current date and time:"
  print str(now)

########## (Can't find anything) ##########
else:
  print("Something goes wrong ;( ")

Error - NameError: name 'date' is not defined

1 Answers1

0

In Python 3

import datetime

x = input("Type your question here ... ")
########## Date ##########
now = datetime.datetime.now()
date = "Date"
if x == date:
  print ("Current date and time:")
  print (str(now))

########## (Can't find anything) ##########
else:
  print("Something goes wrong ;( ")

and the output is:

Type your question here ... Date                                                                                                                              
Current date and time:                                                                                                                                        
2019-07-08 12:53:41.534617     
bart
  • 1,003
  • 11
  • 24