Untitled

 avatar
unknown
plain_text
23 days ago
1.4 kB
4
Indexable
# Function to calculate years required to reach the target rent
def calculate_years(initial_rent, annual_increase, target_amount):
    annual_rent = initial_rent * 12  # Rent for the first year (annual)
    total_rent_paid = 0  # Total rent paid over the years
    years = 0  # Number of years
    
    # Loop until total rent exceeds the target amount
    while total_rent_paid < target_amount:
        years += 1
        total_rent_paid += annual_rent
        annual_rent *= (1 + annual_increase)  # Increase rent by the given percentage each year

    return years, total_rent_paid

# Input section for the user
print("Welcome to the Rent Calculator!")

# Get input values from the user
initial_rent = float(input("Enter your current monthly rent (in rupees): "))
annual_increase_percentage = float(input("Enter the annual rent increase percentage (as a decimal): "))
target_amount = float(input("Enter the target total amount (in rupees): "))

# Convert the percentage into decimal
annual_increase = annual_increase_percentage / 100

# Calculate the number of years and the final total rent paid
years, total_rent_paid = calculate_years(initial_rent, annual_increase, target_amount)

# Output the result
print(f"\nIt will take {years} years for the total rent to reach or exceed ₹{target_amount:.2f}.")
print(f"By the end of {years} years, you will have paid a total of ₹{total_rent_paid:.2f} in rent.")
Leave a Comment