Ramkumar Kashyap wrote:
> Hi all,
>
> I have just started learning to program and am working through the
> Beginning Python from Wrox.
>
> I am working through one of the examples in the books on dictionaries.
> Here is the example.
>
> >>> menu_specials = {"breakfast" : "sausage and eggs",
> ... "lunch" : "split pea soup and garlic bread",
> ... "dinner": "2 hot dogs and onion rings"}
> >>> print "%s" % menu_specials["breakfast"]
> sausage and eggs
> >>> print "%s" % menu_specials["lunch"]
> split pea soup and garlic bread
> >>> print "%s" % menu_specials["dinner"]
> 2 hot dogs and onion rings
>
> I am trying to print out the entire dictionary but am getting an error.
> print "%s %s %s" % menu_specials["breakfast", "lunch", "dinner"]
> Traceback (most recent call last):
> File "<input>", line 1, in <module>
> KeyError: ('breakfast', 'lunch', 'dinner')
Do you understand why you got that error?
>
> I also tried
> print "%s %s %s" % menu_specials["breakfast"], menu_specials["lunch"],
> menu_specials["dinner"]
> Traceback (most recent call last):
> File "<input>", line 1, in <module>
> TypeError: not enough arguments for format string
Do you understand why you got that error?
The first step to getting things right is to understand the error and
relate it to what Python expects.
What are the acceptable right arguments to %? In what way did your 2nd
attempt fail to meet these requirements?
Once you answer that then the fix should be obvious. So give it a try,
then come back for more help.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor