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

  • برمجة بايثون

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"]

الأجوبة

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
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...