4.1.8 - Fortune teller

Copy the following function to Thonny script editor and save it as fortuneTeller :

Execute the code and at the CLI write :

>>> adviseMe ("Meet my friends tonight?")

The script contains two functions. The first getAnswer returns a value, string in this case, that can be used elsewhere. The second one adviseMe creates a random number between 1 and 9, pass this number to the first function and prints the value that is returned.

So the sequence is :

  • We call the function adviseMe 
  • adviseMe creates a random number 
  • adviseMe is passing the random number as a parameter to function getAnswer
  • getAnswer returns a value
  • adviseMe prints the value that was returned from getAnswer

You can follow the sequence using the Debug button.

As an exercise download the fortuneTeller script from here and print the Docstrings of the two functions.