Code seems to be correct but I can't proceed through the section . Can someone please tell me what's wrong with the code?


#1



https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/2/3?curriculum_id=4f89dab3d788890003000096


Replace this line with your code. 
stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}
    
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
}

# Write your code below!
food=[]
ui={}
s=raw_input('enter no.of items you want in the list')
l=int(s)
for i in range (0,l):
    user=raw_input('enter the item')
    u=int(raw_input('enter the quantity of items'))
    ui[user]=u
    food.append(user)
    i+=1
print food
print ui
def compute_bill(food):
    total=0
    for item in food:
        count=ui[item]
        if stock[item]!=0 and count<stock[item] and count>0:
            total=total+ui[item]*prices[item]
            count=count-ui[item]
        elif stock[item]!=0 and count>=stock[item]:
            total=total+stock[item]*prices[item]
        else:
            total=total
    return total
print compute_bill(food)


#2

Hello @samhithalelouch,

You do not need to put code that analyses user input. All you need to do is define the compute bill function. All you need to do in your compute_bill() function is to iterate over the items list, check if the stock is greater than zero, and if it is, add the price of of the item to a variable, and return that variable. Minimalistic code is always the way to go :smile:!


#3

thank you for the reply :slight_smile: but is the code with the user input wrong ? if the logic is correct , errors shouldn't pop up right ?


#4

Hey @samhithalelouch,

every exercise in CodeCademy has a SCT, or a Submission Correctness Test, which checks if your code is correct and if you can pass onto the next round. In this case, I don't think the SCT expects the user to go above and beyond in this exercise. So stick to the instructions precisely, and you'll be good to go!