What is this Indentation Error in this following code

Viewed 11

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

2 Answers

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

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")
Related