获得预期的缩进块错误

时间:2017-11-22 15:36:55

标签: python block

def main():
    name = input("Enter Your Name:")
    name2 = input ("Enter Your Name:")
    if (name == 'Mark') & (name2 == 'John'):
        print("Your Name is correct")

main()

这是我编写的简单代码,仅用于学习Python。但是,我每次都会收到错误。我该怎么解决这个问题?

2 个答案:

答案 0 :(得分:1)

我相信你的打印声明原本不对齐,因为它没有被你的if声明所吸引。您的&也应为and

def main():
    name = input("Enter Your Name:")
    name2 = input ("Enter Your Name:")
    if (name == 'Mark') and (name2 == 'John'):
        print("Your Name is correct")

main()

答案 1 :(得分:-1)

这应该有效

def main():
   name = input("Enter Your Name:")
   name2 = input ("Enter Your Name:")
   if (name == 'Mark') & (name2 == 'John'):
       return("Your Name is correct")

print(main())