简体   繁体   English

以下代码中的这个缩进错误是什么

[英]What is this Indentation Error in this following code

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

If you want to use "try" then you should give indent like this如果你想使用“try”,那么你应该像这样缩进

#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而 python 通常使用 4 个空格进行缩进

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM