第24行出现意外缩进

时间:2019-05-21 01:58:09

标签: python

我编写了一个程序来尝试提出建议并提供一些信用卡提示。该程序似乎被破坏了。在第24行附近,python空闲状态指出此行附近发生了意外的缩进错误:if sw524Y == "Y":

print("Credit card suggestion and credit card tips program")

import sys
while True:
    try:
        rule524 = input("Have you opened 5 or more credit cards in the past 24 months? Please enter Y or N: ")
    except:
        print("Sorry, I didn't understand that. What did you just enter?" "Please try again") 
        continue
    else:
        if rule524 == "Y":
            ruleY()

        def ruleY():
            print("That's not great but you still have options: ")
            print("If you want you can wait until you meet the 5/24 rule and at the same time improving your credit: ")
            print("Try to keep your credit utilization under 30% because banks don't like it when you max out your card. ")
            print("While you are at it never draw money from an ATM with a credit cards. Banks see this as a high risk short term loan and many banks will charge you daily intrest just for having the loan.")
            print("If you try and open more cards you may get denied or have you accounts closed you be careful.")
            print("If you want a travel card if I were you I would get the Barclays AA card")
            cards1 = ["Chase Freedom", "Chase Sapphire Reserve", "Chase Sapphire Preferred", "American Express Gold Card", "Capital One Venture Card"]
            print("Some other great cards to look at are:", *cards1, sep='\n')

            sw524Y = input("Do you want the Southwest Companion Pass?: ")
                if sw524Y == "Y":
                    print("You need to wait because as good as that pass is as a person who is over the 524 you aren't getting it any time soon.")
                if sw524Y == "N":
                    print("You won't get it anyway. Good on you for knowing your limits. Give it time any you may get it one day.")
                if sw524Y != "Y" or "N":
                    print("Please enter valid data next time.")

            cashback()

        def cashback():
            cback = input("Do you want cash back? Enter Y or N. ")
            if cback == "Y":
                print("Okay. I would get either the Arrival+ or the Capital One Venture. Both come with great sign up bonuses. ")

        if rule524 == "N":
            print("Good for you. Now just because you opened under 5 credit cards in the last 24 months doesn't mean you can get any card you want")
            print("Different cards have different rewards so I'm going to need to ask you what options you value most.")
            print("Since you are under the 5/24 rule the recommended rate is 1 card every three months for the most benefits")
            print("There are a few great cards but to get the most benefits you should also be under the 4/24 rule or 4 cards in the last 24 months")
            cardnumber = input("How many cards did you open in the last 24 months?: ")
                if cardnumber <= 2:
                    print("You seem to be on the path to some great cards. You have a lot of flexibility.")
                if cardnumber >=2:
                    print("You have less flexibility but you still have the oportunity to open some great cards")

            cards1 = ["Chase Freedom", "Chase Sapphire Reserve", "Chase Sapphire Preferred", "American Express Gold Card", "Capital One Venture Card"]
            print("While you wait I would look at some of these great cards for the future:", *cards1, sep='\n')


            rule424 = input("Have you opened 4 or more credit cards in the past 24 months? Please enter Y or N: ")
                if rule424 == "Y":
                    ruleY2()

                def ruleY2():
                    print("At least you haven't opened 5 or more cards in the last 24 months but you are essentialy in the same place as the person in the 5/25 category")
                    print("You don't have the option of opening multiple cards in the span of a few months")
                    print("I would get the Ink Preferred card")

当我在Python空闲状态下运行它时,出现意外的缩进错误。

1 个答案:

答案 0 :(得分:0)

对于缩进问题,例如在第24行,您应该写

sw524Y = input("Do you want the Southwest Companion Pass?: ")
if sw524Y == "Y":
    print("You need to ...")

与其缩进if语句,对于在代码中出现此问题的其他地方也应这样做。

但是我不认为这只是缩进的问题(如果您在上面修复了缩进,那么您应该能够运行代码,但是在您做出选择时,它将崩溃),我注意到了这两个问题问题:

  1. 我认为您不能先调用一个函数,然后再对其进行定义
  2. 在第45行和第47行上,您分别写了if cardnumber <= 2:if cardnumber >= 2:,但是cardnumber是input调用的返回值,应该是字符串,我认为您不能做这样的比较。