Python Forum

Full Version: How to use a string method on user input
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
while input("Hit Enter or type \"stop.\" ") != "stop":
I'm trying to make it so that it doesn't matter if the user capitalizes "stop" or puts it in all caps. I've tried

while input("Hit Enter or type \"stop.\" ") != str.lower("stop"):
but that doesn't seem to do anything. I've also tried

while input(str.lower("Hit Enter or type \"stop.\" ")) != "stop":
but that just makes the prompt lower case. Help?
You use string methods on a string, not the str type.

while input("Hit Enter or type \"stop.\" ").lower() != "stop":
Since input returns a string, you can put it to the right of the input call, and it will apply to the return value of input.
(Mar-17-2019, 08:09 PM)ichabod801 Wrote: [ -> ]You use string methods on a string, not the str type.

while input("Hit Enter or type \"stop.\" ").lower() != "stop":
Since input returns a string, you can put it to the right of the input call, and it will apply to the return value of input.

Perfect! Thank you.