Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Discuss the states of accounting

Answered: 1 week ago

Question

3. Write a policy statement to address these issues.

Answered: 1 week ago

Question

2. Why has the conflict escalated?

Answered: 1 week ago