My goal is to have a small program which checks if a customer is approved for a bank loan. It requires the customer to earn > 30k per year and to have atleast 2 years of experience on his/her current job. The values are get via user input. I implemented regexs to validate the input to be only digits without any strigns or negatives, nor 0.
But the 3rd function asses_customer
is always executing the else part. I think everytime the parameters are either None, either 0
here's the source code:
import sys
import re
import logging
import self as selfclass loan_qualifier():# This program determines whether a bank customer# qualifies for a loan.def __init__(self): #creates objectpassdef main():salary_check()work_exp_check()asses_customer(salary = 0, years_on_job = 0)def salary_check():input_counter = 0 # local variable# Get the customer's annual salary.salary = raw_input('Enter your annual salary: ')salary = re.match(r"(?<![-.])\b[1-9][0-9]*\b", salary)while not salary:salary = raw_input('Wrong value. Enter again: ')salary = re.match(r"(?<![-.])\b[1-9][0-9]*\b", salary)input_counter += 1if input_counter >= 6:print ("No more tries! No loan!")sys.exit(0)else:return salarydef work_exp_check():input_counter = 0 #local variable to this function# Get the number of years on the current job.years_on_job = raw_input('Enter the number of ' +'years on your current job: ')years_on_job = re.match(r"(?<![-.])\b[1-9][0-9]*\b", years_on_job)while not years_on_job:years_on_job = raw_input('Wrong work experience. Enter again: ')years_on_job = re.match(r"(?<![-.])\b[1-9][0-9]*\b", years_on_job)input_counter += 1if input_counter >= 6:print ("No more tries! No loan!")sys.exit(0)else:return years_on_jobdef asses_customer(salary, years_on_job):# Determine whether the customer qualifies.if salary >= 30000.0 or years_on_job >= 2:print 'You qualify for the loan. 'else:print 'You do not qualify for this loan. '# Call main()
main()