Q:

Write python program that allows users to enter a list of names, and insert in a list only the name that the first character repeated in the same name, then print the list

0

Write python program that allows users to enter a list of names, and insert in a list only the name that the first character repeated in the same name, then print the list. 

  

Example : 

Please Enter Name: Ahmad 

 #"Ahmad" should be inserted to list letter "a" repeated 

Please Enter Name: Mohammed 

#"Mohammed" should be inserted to list letter "m" repeated 

Please Enter Name: Turki 

#"Turki" shouldn’t be in the list because "t" not repeated 

  

Output :["Ahmad", "Mohammed"]

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import sys

li=[]
while(True):
    name=input('Please Enter Name: ')
    firstchar=name[0]
    repeated=False
    for i in range(1,len(name)):
        if firstchar==name[i]:
            print('"',name,'" should be inserted to list, because letter','"',firstchar,'"',' repeated')
            repeated=True
            li.append(name)
            break
    if repeated==False:
        print('"',name,'" should not be inserted to list because , letter','"',firstchar,'"',' not repeated')
        print(li)
        sys.exit()
        break

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now