Python Forum
Assert Error: AssertionError
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assert Error: AssertionError
#1
Hi!

The function stergereTranzactie(list,zi) delete a number from a list.
The function testarestergereTranzactie() tests stergereTranzactie(list,zi).

How can I solve this error/How can I use "assert" in this situation?


def stergereTranzactie(list,zi):
    del(list[zi])

def testarestergereTranzactie():
    assert (stergereTranzactie([12, 13, 14, 15], 0)==[13, 14, 15])

def mainFunction():
    testarestergereTranzactie()
    
mainFunction()
Error:
Traceback (most recent call last): File "C:/Users/Petru/Desktop/test.py", line 12, in <module> mainFunction() File "C:/Users/Petru/Desktop/test.py", line 9, in mainFunction testarestergereTranzactie() File "C:/Users/Petru/Desktop/test.py", line 5, in testarestergereTranzactie assert (stergereTranzactie([12, 13, 14, 15], 0)==[13, 14, 15]) AssertionError
Thanks!
Reply
#2
stergereTranzactie() does not return anythin (i.e. it returns None).
you want to return the list after you deleted the element.
Note that list is built-in function. NEVER use built-in functions, module or package names as variables
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Ok!
Thank you man, appriciate it, now is ok :D
Reply


Forum Jump:

User Panel Messages

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