Python Synagogue Questions

Asked 2 years ago, Updated 2 years ago, 20 views

I don't know why I get an error.

If I erase the ASSERT and run it, I get Success False, what kind of error is it?

python

2022-09-20 10:55

2 Answers

Hello.

The assert syntax moves on if the subsequent conditions are true, and causes an Assertion Error if false. This means that AssertionError is not due to any technical problems with the code, but because the assert syntax is false.

assert palindrome("racecar") == "Success"
# Palindrome ("racecar") If return value is "Success", pass
# Failure to do so results in an AssertionError

The palindrome function of the body code is supposed to return True/False instead of Success/Fail string. No matter how hard you try to find out the result, it's useless if the return is not delivered because the return is wrong.

If you modify the function to return the execution result of the function, it will work properly.


2022-09-20 10:55

You must return Success or Fail. Don't print.


2022-09-20 10:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.