0

ghfgfghhggkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkWhat is this Indentation Error in this following code

#We first import the datetime module
import datetime
while True:
try:
birthday = input("Enter your Date of Birth(eg. December 25 2005):")
birthday = datetime.datetime.strptime(birth_day, '%B %d %Y')
break
except:
print("Please put in the Format 'Month Day Year' without any initial space")
tday = datetime.datetime.today()
delta = (tday - birthday).total_seconds()
print("You are",delta,"seconds old")

venu
  • 13
  • 1
  • 6
  • Does this answer your question? [I'm getting an IndentationError. How do I fix it?](https://stackoverflow.com/questions/45621722/im-getting-an-indentationerror-how-do-i-fix-it) – Jelmergu Sep 23 '22 at 06:12

2 Answers2

0

If you want to use "try" then you should give indent like this

#We first import the datetime module
import datetime
while True:
    try:
        birthday = input("Enter your Date of Birth(eg. December 25 2005):")
        birthday = datetime.datetime.strptime(birth_day, '%B %d %Y')
        break
    except:
        print("Please put in the Format 'Month Day Year' without any initial space")
tday = datetime.datetime.today()
delta = (tday - birthday).total_seconds()
print("You are",delta,"seconds old")

And python usually use 4 white space for indent

dhkim
  • 81
  • 5
0
import datetime

while True:
    try:
        birthday = input("Enter your Date of Birth(eg. December 25 2005):")
        birthday = datetime.datetime.strptime(birth_day, '%B %d %Y')
        break
    except:
        print("Please put in the Format 'Month Day Year' without any initial space")

tday = datetime.datetime.today()
delta = (tday - birthday).total_seconds()
print("You are",delta,"seconds old")