Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

checking if input1 and input2 is in list of strings

I am trying to print names that equal to inputs

for example :

if input1 = 'A' and input2 = 'G' 
    print("Arsalan Ghasemi")

so my code works but for some names it’s not working

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

if input = ‘S’ and second input = ‘S’ again
it will print 3 names that has ‘S’ in it even they are lowercases

here my code

names = ['Arsalan Ghasemi', 'Ali Bahonar', 'Negin Soleimani', 'Farzaneh Talebi', 'Sina Ghahremani',
         'Saman Sorayaie', 'Abtin Tavanmand', 'Masoud Jahani', 'Roya Pendar', 'Zeynab Arabi',
         'Amirhossein Tajbakhsh', 'Aria Irani']


def names_with_input(input1, input2):
    for i in range(len(names)):
        if input1.upper() in names[i] and input2.upper() in names[i]: 
            print(names[i])

first = input('Enter first letter: ')
last = input('Enter last letter: ')

names_with_input(first, last)

I thought it’s only check upper cases but seems it’s not
how I can fix this when inputs are ‘S’ and ‘S’, it should only give me ‘Saman Sorayaie’

>Solution :

names = ['Arsalan Ghasemi', 'Ali Bahonar', 'Negin Soleimani', 'Farzaneh Talebi', 'Sina Ghahremani',
         'Saman Sorayaie', 'Abtin Tavanmand', 'Masoud Jahani', 'Roya Pendar', 'Zeynab Arabi',
         'Amirhossein Tajbakhsh', 'Aria Irani']


def names_with_input(input1, input2):
    for name in names:
        first_name, last_name = name.split()
        if input1.upper() in first_name[0] and input2.upper() in last_name[0] : 
            print(name)
names_with_input('s','s')

hope this will help for you

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading