CS50P problem set 8 cookie jar check50 Error

142 views Asked by At

I keep getting this error on the check50 while all other tests passes can anyone help me plz.

":( jar's withdraw method removes cookies from the jar's size" Cause expected exit code 0, not 1

here is my code:

class Jar:
    def __init__(self, capacity=12):
        if capacity > 0:
            self._capacity = capacity
            self._size = 0
        else:
            raise ValueError
    
    def __str__(self):
        return f"{self.size * ''}"
    
    def deposit(self, n):
        if n <= self.capacity and n + self.size <= self.capacity:
            self._size += n
        else:
            raise ValueError
    
    def withdraw(self, n):
        if n <= self.capacity and n < self.size:
            self._size -= n
        else:
            raise ValueError

    @property
    def capacity(self):
        return self._capacity
    
    @property
    def size(self):
        return self._size
1

There are 1 answers

0
Hosein Zadeh Mohammadi On

with the help of Time Roberts, the condition on withdraw should be n <= self.size. this is the solution for my probelm