Shady1234's Posts
Nairaland Forum / Shady1234's Profile / Shady1234's Posts
(1) (of 1 pages)
Properties / I'm Looking For A Standard Self Contain Or Mini Flat by shady1234: 4:41pm On Jul 22, 2017 |
I'm looking for a standard self contain or mini flat around ilupeju, palmgrove, obanikoro or anthony axis. It should have tiles, water, good power supply, and the area should be secure (I usually work late nights). If you have any property with the above, drop your number and I will contact you.
Note: If I will be asked to pay 2 years up front, don't bother dropping your contact |
Programming / Re: Please Help With My Python Shopping Cart Script by shady1234: 5:40pm On Mar 15, 2017 |
shady1234: So I have been able to solve this. For those who are still having problems with this test. The problem was in the remove_item method. If you use the supplied quantity to compute the total, you'll get a wrong answer if the quantity supplied is greater than what is already in the cart. The correct remove_item method is:
def remove_item(self, item_name, quantity, price): if item_name and quantity and price: if type(item_name) == str and type(quantity) == int and type(price) == int: if item_name in self.items: if quantity >= self.items[item_name]: self.total -= (self.items[item_name] * price) del self.items[item_name] else: self.items[item_name] -= quantity self.total -= quantity * price
|
Programming / Re: Please Help With My Python Shopping Cart Script by shady1234: 5:40pm On Mar 15, 2017 |
. |
Programming / Please Help With My Python Shopping Cart Script by shady1234: 3:07pm On Mar 15, 2017 |
I applied for the Andela fellowship and have completed all quizzes and labs except this shopping cart lab. My solution has passed all visible tests but I don't know why it's failing to pass the hidden tests. Can anybody tell me what's wrong with my code or what hidden test they think I'm failing? Below is my code class ShoppingCart(object): def __init__(self): self.total = 0 self.items = dict() def add_item(self, item_name, quantity, price): if item_name and quantity and price: if type(item_name) == str and type(quantity) == int and type(price) == int: if item_name in self.items: self.items[item_name] += quantity else: self.items[item_name] = quantity self.total += quantity * price def remove_item(self, item_name, quantity, price): if item_name and quantity and price: if type(item_name) == str and type(quantity) == int and type(price) == int: if item_name in self.items: if quantity > self.items[item_name]: del self.items[item_name] else: self.items[item_name] -= quantity self.total -= quantity * price def checkout(self, cash_paid): if cash_paid and type(cash_paid) == int: if self.total > cash_paid: return "Cash paid not enough" else: return cash_paid - self.total class Shop(ShoppingCart): def __init__(self): self.quantity = 100 def remove_item(self): self.quantity -= 1
|
(1) (of 1 pages)
(Go Up)