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
  Multiple variable inputs when only one is called for ChrisDall 2 449 Oct-20-2023, 07:43 PM
Last Post: deanhystad
  splitting file into multiple files by searching for string AlphaInc 2 815 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  Matching multiple parts in string fozz 31 6,059 Jun-13-2022, 09:38 AM
Last Post: fozz
  Convert string to float problem vasik006 8 3,269 Jun-03-2022, 06:41 PM
Last Post: deanhystad
  Search multiple CSV files for a string or strings cubangt 7 7,842 Feb-23-2022, 12:53 AM
Last Post: Pedroski55
Lightbulb Multiple inputs on the same line (beginner) dementshuk 9 2,716 Sep-03-2021, 02:21 PM
Last Post: dementshuk
  Generate Multiple sql Files With csv inputs vkomarag 13 4,110 Aug-20-2021, 07:03 PM
Last Post: vkomarag
  Replace String in multiple text-files [SOLVED] AlphaInc 5 7,962 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt
  f string concatenation problem growSeb 3 2,212 Jun-28-2021, 05:00 AM
Last Post: buran
Question Problem with string and \n Falassion 6 2,616 Jun-15-2021, 03:59 PM
Last Post: Falassion

Forum Jump:

User Panel Messages

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