Python Python Basics (2015) Number Game App Number Game Refinement

Why do we lowercase play_again @ 7:55?

At 7:55.

play_again 

is lowercased to

play_again.lower()

I tested it out without lower() and it seemed fine? Whats the use of this?

2 Answers

Greg Kaleka
Greg Kaleka
39,007 Points

Hi Ryan,

This is just to make the input case insensitive. The user can enter n or N and the app will quit correctly. If you don't have lower(), then it makes the user input case sensitive.

Hope that makes sense!

Cheers :beers:

-Greg

Greg Kaleka Wouldn't lower() make it case sensitive due to only lowercase answers being allowed?

Greg Kaleka
Greg Kaleka
39,007 Points

It's the opposite. You're checking if the answer was 'n'. If you don't lowercase the input then 'N' won't match. 'N' == 'n' is False. If you do lowercase the input, then both 'n' and 'N' will be accepted answers. 'N' turns into 'n' and 'n' stays as it is. Then you check 'n' == 'n' in both cases which is True. Make sense?

Ari Misha
Ari Misha
19,259 Points

Hiya again! Can you paste the whole code here please? So that other people can inspect it. (:

I suggest to just check out the code @ 7:55.. It's quite hassle for me to write the whole code all over again... is that okay?