Python Forum
Problem with accepting multiple string inputs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with accepting multiple string inputs
#1
Hello guys,

Please see the below
my_name = input("What is your name? ")
my_secondname = input("What is your second name? ")
age = int(input("What is your age? "))

measurement = input("What unit of measurement would you like to use, Imperial or Metric? (imp or met) ")
if measurement == "imp" or "Imperial" or "imperial" or "Imp":
   # if measurement == "imp" or "Imperial" or "imperial" or "Imp":
    imp_weight = int(input("What is your weight? (Numbers only lbs) "))
    imp_height = int(input("What is your height? (Numbers only inches) "))
I would like the input of 'measurement' to equal any variation of the word imperial.

Can anyone assist with this?

I have been told other questions explain this to me but can someone explain it to me in this specific case because i am new to python and will understand it better with my own code.

Thank you,
Ryan
Reply
#2
https://python-forum.io/Thread-Multiple-...or-keyword
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Something like
meas = "IMPerI"
if meas.lower() in "imperial" :
    print("Imp")
else:
    print("Metric")
Reply
#4
try this to see if that helps,

my_name = input("What is your name? ")
my_secondname = input("What is your second name? ")
age = int(input("What is your age? "))
 
measurement = input("What unit of measurement would you like to use, Imperial or Metric? (imp or met) ")
if measurement.lower() == "imp" or "imperial":
   
    imp_weight = int(input("What is your weight? (Numbers only lbs) "))
    imp_height = int(input("What is your height? (Numbers only inches) "))
Output:
python test1.py What is your name? ff What is your second name? hh What is your age? 22 What unit of measurement would you like to use, Imperial or Metric? (imp or met) IMperial What is your weight? (Numbers only lbs) 2 What is your height? (Numbers only inches) 3
Best Regards,
Sandeep

GANGA SANDEEP KUMAR
Reply
#5
(Jan-22-2020, 05:18 PM)sandeep_ganga Wrote: if measurement[:3].lower() == "imp" and measurement.lower() == "imperial":
you don't want to use and. this way imp will not work

measurement = input("What unit of measurement would you like to use, Imperial or Metric? (imp or met) ")
if measurment.lower() in ('imp', 'imperial'):
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
(Jan-22-2020, 05:18 PM)sandeep_ganga Wrote: if measurement.lower() == "imp" or "imperial":
now you replicate OP error :-)
I have shown in my previous post one way
the other is
if measurement.lower() == "imp" or measurement.lower() == "imperial":
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to print string multiple times on new line ace19887 7 189 Sep-30-2020, 02:53 PM
Last Post: buran
  convert string into multiple columns in python3 VAN 2 264 Sep-26-2020, 11:14 PM
Last Post: scidam
  Multi set string inputs/outputs kwmcgreal 2 206 Sep-26-2020, 10:44 PM
Last Post: kwmcgreal
  string problem Mathisdlg 6 572 Aug-05-2020, 09:31 AM
Last Post: Mathisdlg
  Python Hangman Game - Multiple Letters Problem t0rn 4 480 Jun-05-2020, 11:27 AM
Last Post: t0rn
  How to print string multiple times separated by delimiter Mekala 1 317 May-23-2020, 09:21 AM
Last Post: Yoriz
  question: finding multiple strings within string djf123 4 492 May-16-2020, 01:00 PM
Last Post: snippsat
  Accepting inputs str vs int lbtdne 2 295 May-14-2020, 01:45 PM
Last Post: lbtdne
  Split string with multiple delimiters and keep the string in "groups" DreamingInsanity 4 435 May-12-2020, 09:31 AM
Last Post: DeaD_EyE
  How to write a response if a user inputs a string horuscope42 3 494 Apr-29-2020, 03:39 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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