Question: Write a program to ask the user for five names, and later ask if they would like to replace the name in the list. Your

Write a program to ask the user for five names, and later ask if they would like to replace the name in the list. Your program should store the names in a list and print them out at the end.

Sample

Write a program to ask the user for five names, and later

I tried this but didnt work well

name_list=[] #initialise blank list print("Enter Five names") for i in range (0,5,1): x = input() #store input in variable x name_list.append(x) #adds name at end of list print(" >>>The names are "+" ".join(name_list)) #printing list using .join

def yes_or_no(): reply = str(input(' Replacing a name? (yeso): ')).lower().strip() if reply[0] == 'yes': return 1 elif reply[0] == 'no': return 0 else: return input("Please Enter (yeso) ")

if((yes_or_no) == 1): x =(int)(input("Which one? (1-5) ")) -1 #decreasing input by 1 cause list start from 0 name_list[x]= input("New Name: ") #storing input in list print("The names are now "+" ".join(name_list))#printing list using .join print("Thank you for using the program!")

elif((yes_or_no) == 0): print("Thank you for using the program!")

Enter 5 names, press enter key after each one:Snoopy Enter 5 names, press enter key after each one:Charlie Enter 5 names, press enter key after each one:Linus Enter 5 names, press enter key after each one:Woodstock Enter 5 names, press enter key after each one:Lucy The names are: ['Snoopy', 'Charlie', 'Linus', 'Woodstock', 'Lucy'] Replacing a name? Type 'yes' or 'no': yes Type 1-5: 5 new name: Peppermint Patty The names are now: ['Snoopy', 'Charlie', 'Linus', 'Woodstock', 'Peppermint Patty'] Replacing a name? Type 'yes' or 'no': no Thank you for using the program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!