In this code I tried to make that when you type "work", you get any number from 1 to 50 and it adds itself to the total balance (5 times). But when I do this, the previous amount of the variable resets to the new amount.
import random
balance = 0
def work(balance):
    earned_money = random.randint(1, 50)
    balance += earned_money
    print(balance)
for x in range(5):
    user_input = input()
    if user_input == "work":
        work(balance)
 
     
     
    