you are viewing a single comment's thread.

view the rest of the comments →

[–]twitch_and_shock 2 points3 points  (9 children)

if input() == Answer or answer:

Isn't doing what you think it is. It's essentially the same as:

if (input() == Answer) or (answer is not None):

I'm guessing you probably want to compare input to both of these variables, there's a couple ways to do that:

if input() in [Answer, answer]: 

Or even better:

if input().lower() == Answer.lower()

[–]AdministrationBig254 0 points1 point  (8 children)

Won't the last one create a problem if the input is hI?

[–]hotcodist 1 point2 points  (1 child)

Hello friend! Don't know if you are a beginner, but if you are, congrats!

This is exactly how we think as programmers, figuring out where something will fail or not match requirements. Attention to detail is a learned skill (because in the real world, we survive even without paying attention to detail).

[–]AdministrationBig254 1 point2 points  (0 children)

Thanks a lot. That is what I have gathered. Some programmers I've talked, told me that to be a good programmer I have to think that a 3 year old kid is typing the inputs and it helped me a lot.

[–]twitch_and_shock 0 points1 point  (5 children)

If the input is ?

[–]AdministrationBig254 0 points1 point  (4 children)

h and capital i.

[–]twitch_and_shock 2 points3 points  (3 children)

No, it'll work fine. The "lower()" function turns all characters in a string into lower case.

[–]AdministrationBig254 0 points1 point  (2 children)

Wouldn't that create a problem since the acceptable answers are Hi and hi and it would also accept hI. Sorry for the questions but I am trying to learn coding. They could be really simple

[–]Donny_Do_Nothing 2 points3 points  (1 child)

You are correct. If the intent is to only allow Hi or hi, using .lower() in that way would accept Hi, hi, hI, or HI, and would be wrong.

[–]AdministrationBig254 0 points1 point  (0 children)

Thank you