Good Evening,
I have been learning python for about a week now and decided to try and write a financial calculator program (however painstaking due to my complete lack of knowledge. I am having trouble with user input and try:. I would like to restart the program back to user input when the user inputs a str or float rather than an int. I can get the program to print "please use a real number" if they input something other than an int, but I don't know how to get it to restart.
I know my code is probably dreadfully inefficient, and I am still working the calculation at the end for compound interest. (Help appreciated there too!)
Respectfully yours,
Aldi
I have been learning python for about a week now and decided to try and write a financial calculator program (however painstaking due to my complete lack of knowledge. I am having trouble with user input and try:. I would like to restart the program back to user input when the user inputs a str or float rather than an int. I can get the program to print "please use a real number" if they input something other than an int, but I don't know how to get it to restart.
I know my code is probably dreadfully inefficient, and I am still working the calculation at the end for compound interest. (Help appreciated there too!)
Respectfully yours,
Aldi
try: age = int(input("What is your age?")) retirement_age = int(input("At what age would you like to retire?")) except ValueError: print("Please use a whole number") years_to_save = int(retirement_age-age) print(f'You have {years_to_save} years to save.') try: mnth_svng_no_intrest = int(input("How much money will you save per month?")) except ValueError: print("Use a real number, rounded to the tenth") life_svng_no_intrest = int(years_to_save*mnth_svng_no_intrest)*12 print(f'That is great! If you do NOTHING but save that money, you will have ${life_svng_no_intrest} at retirement.') interst_at_ten = (mnth_svng_no_intrest(1*.1)**1)