Python Forum
Help with homework assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with homework assignment
#2
It's all a big mess. The error you are getting is because GroceryList() calls GroceryList.__init__, which specifies three parameters: self, item, and price. The self parameter is provided automatically, but you don't provide an item and price parameter. There are a number of ways you could fix that, but you still have other problems.

But self = {} is just invalid, even if it doesn't cause an error. self refers to the current instance the method is working on. You have just obliterated that, and replaced it with an empty dictionary. That dictionary will just disappear at the end of the method call.

You need to create an attribute that holds the dictionary, probably called prices. I wouldn't start with an item and a price, that doesn't make sense. Then none of the other methods should be class methods. They should all operate on the attribute with the dictionary (self.prices if you called it prices), not on self directly.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Help with homework assignment - by grayarea3 - Feb-20-2019, 09:40 PM
RE: Help with homework assignment - by ichabod801 - Feb-20-2019, 10:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I am completely lost on this homework assignment a36 1 1,778 Feb-21-2022, 06:01 AM
Last Post: buran
  saving issue on homework assignment russoj5 2 2,006 Oct-26-2020, 01:53 PM
Last Post: russoj5
  Homework Assignment Help pinku018 3 3,105 Jun-08-2018, 01:09 PM
Last Post: j.crater
  Homework Assignment Help sphedicl 3 3,325 Jun-08-2018, 12:26 PM
Last Post: pinku018

Forum Jump:

User Panel Messages

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