Python Forum
So many things wrong, it runs but not like its supposed to
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
So many things wrong, it runs but not like its supposed to
#1
##
# Author: Kasherwood
# Date: September 12, 2020
# This program takes several several functions and completes all of the processes of a vending machine.
##

#These doc strings are for the power_on function
""" This function sets the machine up. All values must be stored in order to be accessible to the other functions.
Args:
    name- the name of the product
    price- price of the product
    quantity- amount of cans in the machine
Returns:
    this function does not return anything."""
name = 0
price = 0
name = ""
quantity = 0
money = 0

def power_on(name, price, quantity):
    if price <= 0:
        print("Error. Price cannot be a negative.")
    if quantity <= 0:
        print("Error, No supply")



def set_product_name(new_name):
    """ This function allows operator to set/change the name of product.

    ARGS:
        new_name- new name of the product

    Returns:
        this function has no returns
        """
    name == new_name
    if new_name == "":
        new_name = "undefined"


    print("The new product name is:", new_name)




def add_stock(cans_added):
    global quantity
    if cans_added >= 0:
        quantity = cans_added + quantity
    if quantity > 40:
        print("ERROR! Too many, try again.")
    else:
        print("The new stock is", quantity, "cans")



def set_price(new_price):
    """ This function takes one parameter which defines the new price of the product.
    ARGS:
        new_price- new price of the product.
    returns:
        no returns for this program.
        """
    global price
    if new_price <= 0:
        new_price = 0.01
    price = new_price
    print("The new price is:", price)




def insert_coins(money):
    global quantity
    """ This function interacts with all the global variables. Based on the amount entered the function will act a certain way.
    ARGS:
        coins: The amount entered by the customer
        returns:
            coins: if the machine does not have enough stock all of the money provided will be returned.

            change: the difference in amount of coins provided and the price
            """
    if quantity < 1:
        print("OUT OF STOCK")
        return money
    if money < price:
        print("Not enough money, returning coins")
        return money
    else:
        change = money - price
        quantity -= 1
        print("One can of", name, "vended" )
        print("Change = ", change)
        return change



def empty_coins():
    """ This Function zeros the balance of coins retained by the machine. no ARGS or RETURNS"""
    global money
    coins_removed = money - money
    print("Coins Removed:", money)







def report():
    global name, quantity, price, money
    print( "REPORT:", "\n", "==========", "\n", "Product Name:", name, "\n", "Quantity", quantity,"\n", "Unit Price:", price, "\n", "Balance", money )
THIS IS THE END OF MY CODE DOES ANYONE SEE HOW MY PARAMETERS AND VARIABLE ARENT RETAINING THEIR VALUES. THANK YOU!!!!! ALL OF THE INDENTS ARE CORRECT IN PYZO AND THE CODE RUNS BUT NOT HOW ITS MEANT TO.
Reply


Messages In This Thread
So many things wrong, it runs but not like its supposed to - by kasherwood - Sep-25-2020, 07:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use list to solve things hamalainenjuho 4 2,004 Nov-14-2021, 12:57 PM
Last Post: jefsummers
  Not sure what I'm supposed to be doing here. ukr_nate 5 7,534 Jun-14-2017, 01:47 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020