I'm trying to learn Python and I'm really struggling with getting my code into self-contained functions. Here is an example:
def get_inputs():
sales_amount = float(input("Enter total sales amount: "))
def calculate_discount(sales_amount):
discount_amount = sales_amount * 2
return discount_amount
def output():
print ( discount_amount )
def main():
get_inputs()
calculate_discount(sales_amount)
output()
main()
Running this returns
File "/Users/Desktop/assA3.py", line 17, in <module>
main()
File "/Users/Desktop/assA3.py", line 14, in main
calculate_discount(sales_amount)
NameError: name 'sales_amount' is not defined
I thought the variable sales_amount
was defined by the user input before it is referenced later. I can't figure out what I'm missing.
I apologise for how basic this problem is but I'm clearly misunderstanding something fundamental and I'm just really struggling. Any help would be greatly appreciated. Thanks.