편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2021.05.07

    shopping list 코드 작성


    1. make a list called groceries with the values "banana", "orange", and "apple". Define these two defaultdictionaries:

    stock = {
        "banana": 6,
        "apple": 0,
        "orange": 32,
        "pear": 15
    }
    
    prices = {
        "banana": 4,
        "apple": 2,
        "orange": 1.5,
        "pear": 3
    }
    

    2. Define a function compute_bill that takes one argument food as input. In the function, create a variable total with an initial value of zero. For each item in the food list, add the price of that item to the total. Finally, return the total. Ignore whether or not the item you're billing for is in stock. Note that your function should work for any food list.

    3. Make the following changes to your compute_bill function: While you loop through each item of food, only add the price of the item to the total if the item's stock count is greater than zero. If the item is in stock and after you add the price to the total, subtract one from the item's stock count.

    groceries=["banana", "orange", "apple"]
    
    stock={
        "banana" : 6,
        "apple" : 0,
        "orange" : 32,
        "pear" : 15
        }
    
    prices={
        "banana" : 4,
        "apple" : 2,
        "orange" : 1.5,
        "pear" : 3
        }
    
    groceries = ["banana","apple","orange"]
    
    
    stock = { "banana": 6,
        "apple": 0,
        "orange": 32,
        "pear": 15
    }
    
    prices = { "banana": 4,
        "apple": 2,
        "orange": 1.5,
        "pear": 3
    }
    
    
    def compute_bill(food):
        total = 0
        print
        for item in food:
            if stock[item] > 0:
                total += prices[item]
                stock[item] -= 1
        return total
    
    print(compute_bill(groceries))
    

    이렇게 작성했는데 맞게 했는지를 모르겠어요.

  • 프로필 엽토군님의 편집
    날짜2021.05.06

    shopping list 코드 작성


    1. make a list called groceries with the values "banana", "orange", and "apple". Define these two defaultdictionaries:

    stock = {
        "banana": 6,
        "apple": 0,
        "orange": 32,
        "pear": 15
    }
    
    prices = {
        "banana": 4,
        "apple": 2,
        "orange": 1.5,
        "pear": 3
    }
    

    2. Define a function compute_bill that takes one argument food as input. In the function, create a variable total with an initial value of zero. For each item in the food list, add the price of that item to the total. Finally, return the total. Ignore whether or not the item you're billing for is in stock. Note that your function should work for any food list.

    3. Make the following changes to your compute_bill function: While you loop through each item of food, only add the price of the item to the total if the item's stock count is greater than zero. If the item is in stock and after you add the price to the total, subtract one from the item's stock count.

    groceries=["banana", "orange", "apple"]
    
    stock={
    
        "banana" : 6,
    
        "apple" : 0,
    
        "orange" : 32,
    
        "pear" : 15
    
        }
    
    prices={
    
        "banana" : 4,
    
        "apple" : 2,
    
        "orange" : 1.5,
    
        "pear" : 3
    
        }
    
    groceries = ["banana","apple","orange"]
    
    
    
    stock = { "banana": 6,
        "apple": 0,
        "orange": 32,
        "pear": 15
    }
    
    prices = { "banana": 4,
        "apple": 2,
        "orange": 1.5,
        "pear": 3
    }
    
    
    
    def compute_bill(food):
        total = 0
        print
        for item in food:
            if stock[item] > 0:
                total += prices[item]
                stock[item] -= 1
        return total
    
    print(compute_bill(groceries))
    

    이렇게 작성했는데 맞게 했는지를 모르겠어요

  • 프로필 알 수 없는 사용자님의 편집
    날짜2021.05.06

    shopping list 코드 작성


    1. make a list called groceries with the values "banana", "orange", and "apple". Define these two defaultdictionaries: stock = { "banana": 6, "apple": 0, "orange": 32, "pear": 15 }

    prices = { "banana": 4, "apple": 2, "orange": 1.5, "pear": 3 }

    1. Define a function compute_bill that takes one argument food as input. In the function, create a variable total with an initial value of zero. For each item in the food list, add the price of that item to the total. Finally, return the total. Ignore whether or not the item you're billing for is in stock. Note that your function should work for any food list.
    2. Make the following changes to your compute_bill function: While you loop through each item of food, only add the price of the item to the total if the item's stock count is greater than zero. If the item is in stock and after you add the price to the total, subtract one from the item's stock count. groceries=["banana", "orange", "apple"]

    stock={

    "banana" : 6,
    
    "apple" : 0,
    
    "orange" : 32,
    
    "pear" : 15
    
    }
    

    prices={

    "banana" : 4,
    
    "apple" : 2,
    
    "orange" : 1.5,
    
    "pear" : 3
    
    }
    

    groceries = ["banana","apple","orange"]

    stock = { "banana": 6, "apple": 0, "orange": 32, "pear": 15 }

    prices = { "banana": 4, "apple": 2, "orange": 1.5, "pear": 3 }

    def compute_bill(food): total = 0 print for item in food: if stock[item] > 0: total += prices[item] stock[item] -= 1 return total

    print(compute_bill(groceries))

    이렇게 작성했는데 맞게 했는지를 모르겠어요