This repository was archived by the owner on Apr 24, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,11 +19,9 @@ def main():
1919 print ("Welcome to the Loan Calculator!" )
2020
2121 # Get user input
22- principal = float (input ("Enter the loan amount: $" ))
23- annual_interest_rate = float (
24- input ("Enter the annual interest rate (as a percentage): " )
25- )
26- months = int (input ("Enter the loan term (in months): " ))
22+ principal = floatValidation ("Enter the loan amount: $" )
23+ annual_interest_rate = floatValidation ("Enter the annual interest rate (as a percentage): " )
24+ months = intValidtaion ("Enter the loan term (in months): " )
2725
2826 # Calculate monthly payment
2927 monthly_payment = calculate_loan_payment (principal , annual_interest_rate , months )
@@ -32,5 +30,22 @@ def main():
3230 print (f"Your monthly payment will be: ${ monthly_payment :.2f} " )
3331
3432
33+ def floatValidation (question ):
34+ while True :
35+ try :
36+ value = float (input (question ))
37+ return value
38+ except ValueError :
39+ print ('Input should be a valid number' )
40+ continue
41+
42+ def intValidtaion (question ):
43+ while True :
44+ try :
45+ value = int (input (question ))
46+ return value
47+ except ValueError :
48+ print ('Input should be a valid number' )
49+
3550if __name__ == "__main__" :
3651 main ()
You can’t perform that action at this time.
0 commit comments