2

How do I update the user score using return and for loops

 2 years ago
source link: https://www.codeproject.com/Questions/5332311/How-do-I-update-the-user-score-using-return-and-fo
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

See more:

Copy Code
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
Copy Code
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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK