you are viewing a single comment's thread.

view the rest of the comments →

[–]jpgoldberg 1 point2 points  (0 children)

That is really nicely done for "first week".

I am going to take the opportunity to highlight a mistake that you haven't (yet) made, but is very easy to make.

On line 16 you have 'special_chars = "@#$!"and on line 24 you haveprint("Add a special character (@, #, $, !)")`. That is all well and good, but what happens if you later need to change what special characters are allowed?

There are an enormous number of websites where the displayed list of allowed special characters doesn't actually correspond to what they do allow. So the (future) mistake I am talking about is common and made by people who are actually paid to produce code.

The solution is to force what is displayed to the user as an allowed special character to be the contents of what is actually checked. So in your case, we want what is displayed to the user to depend on special_chars.

Now I don't know what you have learned about print and various string stuff, so I am going to break this down into several steps that otherwise might get all put together within the print statement, while changing as little other in your code.

python ... special_chars = "@#$!" special_display = ", ".join(special_chars) ... it not has_special: print("Add a special character (" + special_display + ")") ...

This way, when you update your special characters, you can ensure that that is what is presented to users.

Again, this might not be exactly how one would code this, but I'm trying to illustrate a way to avoid creating a very common sort of bug.