Cris9
Cris9

Reputation: 1

Python: Can't seem to insert an input into a list properly for me to eventually print 2 separate lists. Lists with 'a' names and non-a names

print("This program is made to check to see if your name has a letter 'a' in it.\n")

list_of_names = ["Cris", "Tom", "Tim", "Cali", "Pearson", "Danny", "Anders", "Britney"]
a_list = []
non_a_list = []

while len(list_of_names) < 11:
    input_name = input("What is your name? ")
    
    list_of_names.append(input_name)
    
    
    #print(list_of_names)
    
    #This Checks if the letter 'a' is in the name and puts them into separate lists. 
for name in list_of_names:
    if "a" or "A" in name:
        a_list.insert(0,name)
        
    elif not "a" and "A" in name:
        non_a_list.insert(0,name)

 
print(f"{a_list} do have an 'a'." )
print(f"{non_a_list} don't have an 'a'." )

I added the empty lists on top and the original list is getting the inputted names but once I print, it doesn't print the two separate lists with the print f I created. yes, I'm a noob. 1 week strong

Upvotes: 0

Views: 26

Answers (1)

Yash Mehta
Yash Mehta

Reputation: 2006

Changes made: just change the conditions of if else in checking list_of_names.

Code:-

print("This program is made to check to see if your name has a letter 'a' in it.\n")

list_of_names = ["Cris", "Tom", "Tim", "Cali", "Pearson", "Danny", "Anders", "Britney"]
a_list = []
non_a_list = []

while len(list_of_names) < 11:
    input_name = input("What is your name? ")
    list_of_names.append(input_name)
    #print(list_of_names)
    #This Checks if the letter 'a' is in the name and puts them into separate lists. 
for name in list_of_names:
    if "a" in name or "A" in name:
        a_list.insert(0,name)
        
    else:
        non_a_list.insert(0,name)

print(f"{a_list} do have an 'a'." )
print(f"{non_a_list} don't have an 'a'." )

Output:-

This program is made to check to see if your name has a letter 'a' in it.
What is your name? Yash
What is your name? teneth
What is your name? movre
['Yash', 'Anders', 'Danny', 'Pearson', 'Cali'] do have an 'a'.
['movre', 'teneth', 'Britney', 'Tim', 'Tom', 'Cris'] don't have an 'a'.

Upvotes: 0

Related Questions