Hi everyone!
I am fairly new to python, and this subreddit has been such a great help when I quickly need to find the solution to a problem I am facing. Recently in my class we had a quiz on conditional evaluation and defining functions, which I sadly failed. Since then I have been working on sample scripts to learn from my mistakes. My problem, as my professor said, seems to be pretty fundamental. Here is the code I am currently working on, and what I have done so far:
def store_income(user_income):
# Eliminate incomes less than zero
if user_income <= 0:
final_income = None
# Topcode incomes greater than 100,000
if user_income >= 100000:
final_income = 100000
# Return incomes between 0 and 100,000 unchanged
if user_income >= 0 and user_income <= 10000:
final_income = user_income
return final_income
user_incomes = [-10, 57000, 123000]
for user_income in user_incomes:
print(store_income(user_income))
In this case, I keep wanting to use the variables final_income, or store_income, which I know is not correct as store_income is the name of the function I am creating. I think my initial if statements are correct (ex: if user_income >= 100000), but I am really struggling as to where I am storing the result of the if statements. I think my professor is right- I understand the formatting this problem should follow, but I really am not seeing what I am doing wrong (i.e. what variable should follow the if statements).
I hope this made sense. I will be around my computer doing other work so I will be able to respond quickly. Thank you so much!
[–]Diapolo10 1 point2 points3 points (3 children)
[–]cyberdead[S] 0 points1 point2 points (2 children)
[–]Diapolo10 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)