Python Forum
Ending loop with string (capital & lowercase)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ending loop with string (capital & lowercase)
#1
custname = input("Enter customer's name: ")
while custname.lower () != "QUIT":

I am needing to end the loop when customer's name is "Quit", "quit", and "QUIT". Currently, I have yet to even come close to the desired end of the loop using these names. Any help/guidance would be greatly appreciated!
Reply
#2
you are right to use lower(), however, why you want it to be different from ALL CAPS QUIT
 :-)
Reply
#3
Thanks! I was asked to include these variations in order to make the script easier to use for end-users...
Reply
#4
Perhaps:
quit = ['q', 'Q', 'quit', 'Quit', 'QUIT']
then test if 'custname' is in 'quit'
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Text conversion to lowercase is not working ineuw 3 401 Jan-16-2024, 02:42 AM
Last Post: ineuw
  While loop not ending (Best of 10 dice game) K3nidi 3 1,457 Jul-09-2022, 09:53 AM
Last Post: K3nidi
  python-docx- change lowercase to bold, italic Tmagpy 0 1,353 Jul-01-2022, 07:25 AM
Last Post: Tmagpy
  Loop through a list of string oldtrafford 4 1,424 Mar-24-2022, 05:30 PM
Last Post: deanhystad
  Loop through a list of string oldtrafford 3 1,658 Feb-15-2022, 04:42 PM
Last Post: snippsat
  loop for dynamic cut string - cleaner way? korenron 4 1,877 Nov-22-2021, 02:30 PM
Last Post: korenron
  I am trying to reverse a string using loop codinglearner 4 2,128 Sep-28-2021, 10:46 PM
Last Post: Pedroski55
  Convert string to JSON using a for loop PG_Breizh 3 2,897 Jan-08-2021, 06:10 PM
Last Post: PG_Breizh
  String slicing and loop iteration divyansh 9 4,624 Jun-07-2020, 10:29 PM
Last Post: divyansh
  Ending the Program Twoshawns 2 2,054 May-19-2020, 02:24 AM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020