首页 > 解决方案 > Python:“IndentationError:unindent 不匹配任何外部缩进级别”尝试排除故障但不起作用

问题描述

当我运行我的代码时,即使我没有看到任何错误请帮助

def savings_tracker():
 input("This program will tracker your savings progress. (Press Enter to Continue)")
 goal = input("What are you trying to save for?")
 final_savings_amount = float(input("What is the total amount of money needed to each your goal"))
 monthly_savings = float (input("What is your monthly savings?"))
 current_savings = float(input("What have you saved so far?"))

 month_to_reach_goal = (final_savings_amount-current_savings)/monthly_savings

 month_to_reach_goal = math.ceil(month_to_reach_goal)

 print("The time it will take to get to your goal of",  goal, "is", month_to_reach_goal, "months!")
 print("Your getting there! Keep on saving!")

标签: python

解决方案


我相信这对你有用:

import math
def savings_tracker():
    input("This program will tracker your savings progress. (Press Enter to Continue)")
    goal = input("What are you trying to save for? ")
    final_savings_amount = float(input("What is the total amount of money needed to each your goal "))
    monthly_savings = float (input("What is your monthly savings ?"))
    current_savings = float(input("What have you saved so far? "))

    month_to_reach_goal = (final_savings_amount-current_savings)/monthly_savings

    month_to_reach_goal = math.ceil(month_to_reach_goal)

    print(f"The time it will take to get to your goal of {goal} is {month_to_reach_goal} months!")
    print("You're getting there! Keep on saving!")

savings_tracker()

输入:

This program will tracker your savings progress. (Press Enter to Continue)
What are you trying to save for? a house
What is the total amount of money needed to each your goal 250000
What is your monthly savings? 6000
What have you saved so far? 50000

输出:

The time it will take to get to your goal of a house is 34 months!
You're getting there! Keep on saving!

推荐阅读