我的目标是创建一个小程序来检查客户是否被批准用于银行贷款。它要求客户每年赚取> 3万美元,并且在他/她目前的工作上拥有至少2年的经验。这些值是通过用户输入获取的。我实现了正则表达式来验证输入是没有任何符号或负数的数字,也不是0.无法将函数返回的值传递给python中的另一个函数
但是第三个函数asses_customer
总是执行else部分。我觉得每次的参数或者是无,要么0
这里的源代码:
import sys
import re
import logging
import self as self
class loan_qualifier():
# This program determines whether a bank customer
# qualifies for a loan.
def __init__(self): #creates object
pass
def 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 += 1
if input_counter >= 6:
print ("No more tries! No loan!")
sys.exit(0)
else:
return salary
def 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 += 1
if input_counter >= 6:
print ("No more tries! No loan!")
sys.exit(0)
else:
return years_on_job
def 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()
只是供参考,[当你在你的问题中提供诸如“HELP”或“URGENT”之类的东西时,人们不喜欢](https://meta.stackoverflow.com/a/326590/7662085)。 – stybl
下次会记住,谢谢 – Sosomqk
你只能用'asses_customer(salary = 0,years_on_job = 0)'调用'asses_customer';你期望的参数是什么? (另外,动词“评估”最后用两个S拼写;一个S给你一串驴子。) – jwodder