Help with my codecademy python script

A forum for general discussion of the Python programming language.

Help with my codecademy python script

Postby rodguardia » Tue Jun 24, 2014 12:52 pm

Hi, I will appreciate any help that can come my way.

I am doing an excercise where the script is supposed to get item prices from a shopping list dictionary and come up with a total.

this is the code I have so far:

Code: Select all
shopping_list = ["banana", "orange", "apple"]

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

# Write your code below!
def compute_bill(food):
    total = 0
    for item in shopping_list:
        total += prices[item]
    return total
    print total


And this is the error I am getting:
Oops, try again. You code does not seem to work when ['apple'] is used as input--it returns 7.5 instead of 2.


Does this make sense to you? I wanted to get help outside the discussion boards as most of the people that respond are very near my own level.
Last edited by stranac on Tue Jun 24, 2014 1:04 pm, edited 1 time in total.
Reason: First post lock.
rodguardia
 
Posts: 1
Joined: Tue Jun 24, 2014 12:43 pm

Re: Help with my codecademy python script

Postby lp2014 » Tue Jun 24, 2014 3:15 pm

Are you serious that your code is from codeacademy python script?
I never see python code with this: " { } ".
Don't be stupid when you are!
Last edited by Yoriz on Tue Jun 24, 2014 4:00 pm, edited 1 time in total.
Reason: First post lock.
lp2014
 
Posts: 2
Joined: Tue Jun 24, 2014 2:52 pm

Re: Help with my codecademy python script

Postby Yoriz » Tue Jun 24, 2014 4:01 pm

lp2014 wrote:I never see python code with this: " { } ".

You haven't seen much python code then.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 781
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Help with my codecademy python script

Postby lp2014 » Tue Jun 24, 2014 6:09 pm

@ Yoriz wrote:
"You haven't seen much python code then."


You right.I am wrong here.Dictionaries use curly braces.
I couldn't grab it in my last post.
lp2014
 
Posts: 2
Joined: Tue Jun 24, 2014 2:52 pm

Re: Help with my codecademy python script

Postby Mekire » Tue Jun 24, 2014 11:40 pm

Hi, I will appreciate any help that can come my way.
Back to the issue here. Could you please link to the specific Code Academy problem you are on so we can test it?

-Mek
User avatar
Mekire
 
Posts: 986
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Help with my codecademy python script

Postby Kebap » Wed Jun 25, 2014 10:35 am

Hi Rod, welcome to python!

Yes, that error does make sense to me.

When ['apple'] is used as input, in which variable will this list be saved? And then, how do you use this list to calculate the total price?

You don't. Simple clerical mistake.
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 387
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe


Return to General Discussions

Who is online

Users browsing this forum: Google [Bot] and 2 guests