Cannot pass returned values from function to another function in python

2024/10/6 5:58:38

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()
Answer

You have stated:

It requires the customer to earn > 30k per year and to have at least 2 years of experience on his/her current job.

We can write some simple statements that request a number and if a number is not given then ask for that number again.

The following code is a very simple approach to achieving that goal.

class Loan_Checker():def __init__(self):self.salary = 0self.years_on_job = 0self.request_salary()self.request_years()self.check_if_qualified()def request_salary(self):x = raw_input('Enter your annual salary: ')try:self.salary = int(x)except:print("Please enter a valid number")self.request_salary()def request_years(self):x = raw_input('Enter the number of years on your current job: ')try:self.years_on_job = int(x)except:print("Please enter a valid number")self.request_years()def check_if_qualified(self):if self.salary >= 30000 and self.years_on_job >= 2:print 'You qualify for the loan. 'else:print 'You do not qualify for this loan. 'Loan_Checker()
https://en.xdnf.cn/q/118989.html

Related Q&A

What is the difference here that prevents this from working?

Im reading a list of customer names and using each to find an element. Before reading the list, I make can confirm this works when I hard-code the name,datarow = driver.find_element_by_xpath("//sp…

How can I extract numbers based on context of the sentence in python?

I tried using regular expressions but it doesnt do it with any context Examples:: "250 kg Oranges for Sale" "I want to sell 100kg of Onions at 100 per kg"

Chart with secondary y-axis and x-axis as dates

Im trying to create a chart in openpyxl with a secondary y-axis and an DateAxis for the x-values.For this MWE, Ive adapted the secondary axis example with the DateAxis example.from datetime import date…

Env var is defined on docker but returns None

I am working on a docker image I created using firesh/nginx-lua (The Linux distribution is Alpine): FROM firesh/nginx-luaCOPY ./nginx.conf /etc/nginx COPY ./handler.lua /etc/nginx/ COPY ./env_var_echo.…

No Browser is Open issue is coming when running the Robot framework script

I have created Test.py file which has some function in it and using those function names as Keywords in sample.robot file. Ex: - Test.pydef Launch_URL(url):driver.get(url)def article(publication): do…

How to run python file in Tkinter

Im a beginner in Python, hence the question. i would like to run a python file (smileA.py) in Tkinter. How would i start? I do not wish for it to run when clicking a button, but the file to run automa…

Discord.py Cogs “Command [ ] is not found”

I am recoding my discord.py bot using cogs as it wasnt very nice before. I tried this code: import discord import os import keep_alive from discord.ext import commands from discord.ext.commands import …

Binomial distribution CDF using scipy.stats.binom.cdf [duplicate]

This question already has answers here:Alternatives for returning multiple values from a Python function [closed](14 answers)Closed 2 years ago.I wrote below code to use binomial distribution CDF (by u…

How to get Cartesian product of two iterables when one of them is infinite

Lets say I have two iterables, one finite and one infinite:import itertoolsteams = [A, B, C] steps = itertools.count(0, 100)I was wondering if I can avoid the nested for loop and use one of the infinit…

Function to create nested dictionary from lists [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…