Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to use a string method on user input
#1
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?
Quote
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
(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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Help w/ Max/Min User Input Code ThatGreatState 2 77 Nov-26-2019, 02:52 PM
Last Post: ichabod801
  input string split Eric7Giants 3 112 Nov-13-2019, 07:19 PM
Last Post: Gribouillis
  User input to calculate Area or Radius of Circle DustinKlent 3 122 Nov-10-2019, 08:46 AM
Last Post: Gribouillis
  Help with calling list from user input farispython 5 174 Nov-03-2019, 03:13 PM
Last Post: Gribouillis
  Find Average of User Input Defined number of Scores DustinKlent 1 125 Oct-25-2019, 12:40 AM
Last Post: Larz60+
  with input remove a string from the list konsular 3 155 Oct-12-2019, 09:25 AM
Last Post: konsular
  If Else Statement with User Input CalPark16 1 173 Sep-19-2019, 06:54 PM
Last Post: Axel_Erfurt
  How to run a method on an argument in a formatted string Exsul 1 107 Aug-30-2019, 01:57 AM
Last Post: Exsul
  Creating csv header from user-input list dvanommen 2 264 Aug-26-2019, 08:51 PM
Last Post: dvanommen
  simple string & input problem kungshamji 5 383 Jun-23-2019, 03:54 PM
Last Post: kungshamji

Forum Jump:


Users browsing this thread: 1 Guest(s)