[Python] Im trying to make a reciept maker with code and i don't know how to get my different...

Discussão em 'Python' iniciado por Stack, Março 24, 2025.

  1. Stack

    Stack Membro Participativo

    #The total will be the price paid by the customer after the discount and the tax.
    #Create a main function, getItem function, getDiscount function, getTaxRate function
    #getTotal function. #Use pass through variables.


    trying to make this little project to improve my knowledge but idk how to properly use the return function to make this work

    print ("*****Jeremy's BBQ for You*****")
    import datetime
    now = datetime.datetime.now()
    print(" ",now)
    def main ():
    getItem()
    getItem2()
    getDiscount()
    getTaxrate()
    getTotal()
    def getItem():
    item_name = input("Enter in the name of the purchased item: ")
    def getItem2():
    item_price = float(input("Enter the price of the item being purchased: "))
    print (item_price)
    def getDiscount():
    store_discount = item_price * float(.1)
    print ("You are recieving a 10% discount of: ",store_discount)
    return item_price
    def getTaxrate():
    tax_rate = item_price* float(.06)
    def getTotal():
    total = item_price+store_discount+tax_rate
    main()
    print ("6% Tax")


    this is the error i get when i try and run the code. I'm assuming it because I'm not properly defining my functions so that the can be re referenced to its the return function i need right and how do i insert it. do i also have to add in the variables in the () when defining the functions while adding the return.

    Traceback (most recent call last):
    File "/home/main.py", line 37, in <module>
    main()
    File "/home/main.py", line 20, in main
    getDiscount()
    File "/home/main.py", line 30, in getDiscount
    store_discount = item_price * float(.1)
    ^^^^^^^^^^
    NameError: name 'item_price' is not defined

    Continue reading...

Compartilhe esta Página