Issue
def try_again():
play_again = input("would you like to play again? ").lower()
if play_again == "y":
global comp_count
comp_count = 0
global user_count
user_count = 0
game()
else:
print(" Thanks for playing! Bye now! :) ")
exit()
This is in Python 3. I'd like to reset a global variable in a function. How come I have to call it that way? Is there a better DRY way?
Solution
When a variable is made outside a function, it is set to global by default, but if you create a variable inside a function, and you want the variable to be accessed and changed by other functions, you set it to global.
Answered By - ReplitUser
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.