-2

I'm trying to make a function that writes the scores of a user's quiz to a file along with their username. However the variable that the username is stored in was created inside a different function - how do I use a variable from one function in another function?

H. Duncan
  • 9
  • 2
  • Please provide some code that you have written as a minimum verifiable example. – Austin A Oct 18 '17 at 17:07
  • Rather than describing your code, can you please give a representative example? Please see how to create a [Minimal, Complete and Verifiable Example](https://stackoverflow.com/help/mcve). – roganjosh Oct 18 '17 at 17:07
  • Possible duplicate of [Using global variables in a function other than the one that created them](https://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them) – G. Nachtigal Oct 18 '17 at 17:08
  • @G.Nachtigal I guess that's a correct duplicate target but then again it also uses `global` which I think should be avoided if possible; the OP would _presumably_ be better `return`ing a value from the first function. Then again, we have no solid basis to make the call because there's no code. – roganjosh Oct 18 '17 at 17:11
  • If it is a local variable (which it probably *should* be) then you should be returning the value – juanpa.arrivillaga Oct 18 '17 at 17:48

1 Answers1

0

Normally, you pass parameters to functions and return values

username = get_username()
write_results(username)
FreshPow
  • 6,782
  • 1
  • 15
  • 17