Skip to main content
2 of 5
added 242 characters in body
Reinderien
  • 71.1k
  • 5
  • 76
  • 256
  • Keep fractional variables (0-1) instead of percentile variables (0-100) as the former are more "math-native" and can use in-built percent formatting
  • Try to make your prompts follow a more consistent lexical pattern; the example I've shown has a single "Enter" prompt at the top followed by a series of object phrases
  • Use built-in currency formatting. I have no way of knowing if my guessed hi_IN is accurate for you, but it does offer a rendered rupee symbol. Prefer this symbol over hard-coding and spelling out "rupees". One of the several advantages of locale support is that it correctly renders the (interesting!) lakh digit group separation.
  • Use Python 3.

Suggested

from locale import setlocale, LC_ALL, currency, localeconv
setlocale(LC_ALL, 'hi_IN.UTF-8')
symbol = localeconv()['currency_symbol']

print('Enter...')
salary = float(input(f'your monthly salary: {symbol}'))
savings = float(input('your monthly savings: %'))/100
emi = float(input('your equated monthly installment (EMI): %'))/100
budget = float(input(f'the total amount you want to save: {symbol}'))
duration = float(input('how many months you have: '))


def fmoney(money: float) -> str:
    return currency(money, grouping=True)


tfinal = salary - savings*salary    # total salary left after savings are subtracted
final_left = tfinal - emi*salary    # total salary left after savings and emi removed
percent_left = 1 - savings - emi    # total percentage of salary left after savings and emi removed in percent
final_budget = final_left*duration  # monthly saving multiplied by duration for final amount left
sav_per_month = budget/duration     # final budget savings you are planning per month

if sav_per_month < final_left:
    print(
        'It is possible.'
        f'\nEarning {fmoney(final_left)} with {percent_left:.1%} left,'
        f' you can save {fmoney(sav_per_month)} per month.')
else:
    print(
        'It is not possible.'
        f'\nEarning {fmoney(final_left)} with {percent_left:.1%} left,'
        f' you cannot save {fmoney(sav_per_month)} per month.'
    )

print(f'You will be left with {fmoney(final_budget)}.')

Output

Enter...
your monthly salary: ₹50000
your monthly savings: %5
your equated monthly installment (EMI): %15
the total amount you want to save: ₹100000
how many months you have: 3
It is possible.
Earning ₹40,000.00 with 80.0% left, you can save ₹33,333.33 per month.
You will be left with ₹1,20,000.00.
Reinderien
  • 71.1k
  • 5
  • 76
  • 256