Jump to content

Peabody Wormsworth


peawormsworth

Recommended Posts

I believe this page: https://www.w3schools.com/python/ref_keyword_assert.asp has incorrect wording on the 2nd example. The assertion checks for the presence of 'goodbye' in x, but the message says that "x should be 'hello'". When the assertion is false the error message will appear. However, the message says it should be 'hello' when IT IS 'hello'. That is not logical according to the english words used in the error message. I think the code should be:

 

x = "goodbye"

#if condition returns False, AssertionError is raised:
assert x == "hello", "x should be 'hello'"

It will report "x should be 'hello'" when x is NOT hello.

It says the opposite of what it means when you run it here: https://www.w3schools.com/python/trypython.asp?filename=demo_ref_keyword_assert2

Link to comment
Share on other sites

You should use the "Report error" link at the bottom of the page in question so that the staff can be made aware of the issue. They almost never visit the forums.

Link to comment
Share on other sites

How I read it is

x = "hello" #set variable value

#if condition returns False, AssertionError is raised:
assert x == "goodbye", # compare with condition that set value is equal to "goodbye" which is false

"x should be 'hello'" #on false shows message what the variable value is set to, and that it should be "hello"
Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...