15,358,440 members
See more:
`I am attempting to update the user score using return and for loops, the program is supposed to run 3 times and ask the user for the action they select, after every run the program should print the updated score. For instance, if a user selects hide their score is increased by 300 and it is printed, if they select hide again their score is once again increased. However, in this program, I keep getting the same number every time I run the program with the input "hide". Could someone accept this challenge and help me out?`

Python
```def userCalc():
score=200

for i in range(3):
for userI in range(3):
action= input("Enter (hide or run): ")

def userF(fil):
if fil=="hide":
update= score+200
print (update)
if fil=="run":
update= score+300
print (update)
userF(action)

return action

return score
userCalc()```

What I have tried:

I have tried creating a return statement but it did not work.
Posted
Updated 17-May-22 20:16pm
Patrice T 18-May-22 2:23am

Show code that we can run.

## Solution 1

A couple of things:
1) You don't change `score` at any point, so it will remain at 200 for all time. Probably you want to add to it's value instead of creating a new variable called `update`.

2) `return` causes an immediate exit from the function, no further code is ever executed. So having any code (even another `return` after it is redundant because that later code will never be executed:
```return action

return score
```

3) Both your `return` statements are inside the outer loop, so the outer loop will never execute more than once.

Basically, stop guessing and start thinking! This may help you to get started properly: How to Write Code to Solve a Problem, A Beginner's Guide[^]
CPallini 18-May-22 2:15am

5.

## Solution 2

Try
Python
```def userCalc():
score = 200

def userF(fil, score):
if fil=="hide":
update= score+200
elif fil=="run":
update= score+300
print (update)
return update

for i in range(3):
action= input("Enter (hide or run): ")
score = userF(action, score)
return score

print("final score {}".format(userCalc()))```