You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What format of the book has this error? You may select more than one option.
Print
What language of the book has this error?
English (EN)
Page Number or Section
Chapter 5, pages 108-109
Detailed description
I have a Russian translation of the book from the publishing house DMK Press, but since it is not among the available options, I chose English.
The book contains the code:
userName = input("What is your name? ")
while userName != "Clark Kent":
print("You're not superman - try again!")
userName = input("What is your name? ")
print("You are superman!")
I don't think we should teach people to duplicate code, so I would suggest the following option:
while True:
userName = input("What is your name? ")
if userName == "Clark Kent":
print("You are superman!")
break
else:
print("You're not superman - try again!")
It is more correct and also introduces a new loop break operator.
I would also add an alternative option with match case, which is available since Python 3.10
while True:
userName = input("What is your name? ")
match userName:
case "Clark Kent":
print("You are superman!")
break
case _:
print("You're not superman - try again!")
Unfortunately, the repository does not contain all the code from the book, otherwise I would have made a correction myself and created a pull request.
The text was updated successfully, but these errors were encountered:
Contact Details
No response
What format of the book has this error? You may select more than one option.
Print
What language of the book has this error?
English (EN)
Page Number or Section
Chapter 5, pages 108-109
Detailed description
I have a Russian translation of the book from the publishing house DMK Press, but since it is not among the available options, I chose English.
The book contains the code:
I don't think we should teach people to duplicate code, so I would suggest the following option:
It is more correct and also introduces a new loop
break
operator.I would also add an alternative option with
match case
, which is available since Python 3.10Unfortunately, the repository does not contain all the code from the book, otherwise I would have made a correction myself and created a pull request.
The text was updated successfully, but these errors were encountered: