Skip to content
Advertisement

I cannot pass a parameter inside a function to another function (Python)

I successfully defined a parameter and passed it to a function but when I return to main menu that parameter’s value is completely reset and I cannot use it anywhere. The value of the parameter stays only within the second function. Like, the parameter cannot communicate with the whole program as far as I understand.

JavaScript

For this project’s sake, I don’t want to use global variables. I only want to use the subtotal variable as a parameter throughout the program and continuously alter its value throughout the program and make calculations with it. I want to do this by passing it through other functions.

Advertisement

Answer

Since you’ve written the operations into functions and you’re passing in the current subtotal, you just need to be updating the subtotal by saving the return value from appetizers() in main_menu(), like here:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement