'Returning user score based on an action using Returns and Print
I am trying to create an action game where the user is prompted with 3 options, when the user selects a specific action for instance drinking would add 10 points to the first and second score, I tried returning the user input and calculating it, however, I keep getting the same number 410 when I enter the drinking action the score does not increase, for this question I must use a return. Can someone help?
def main():
userStat1 = 400
userStat2 = 400
for tries in range(3):
def userQ():
asking = input ("Enter drink, run, jump: ")
def userScore():
if userAsk== "drink":
userStat1 + 10
userStat2 + 10
print (userStat1, userStat2)
return userStat1 and userStat2
if userAsk== "run":
userStat1 + 60
userStat2 +50
print (userStat1, userStat2)
return userStat1 and userStat2
if userAsk== "jump":
userStat1 + 30
userStat2 + 40
print (userStat1, userStat2)
return userStat1 and userStat2
print ("your final score is", userStat, userStat2)
userScore()
return asking
askingUser()
main()
Solution 1:[1]
You cannot do userStat+10. You must do userStat+=10 which is short form for userStat=userStat+10
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TheRavenSpectre |
