The top 3 most popular male names of 2017 are Oliver, Declan, and Henry according to babynames. Write a program that modifies the male_names set by removing a name and adding a different name. Sample output with inputs: 'Oliver' 'Atlas' { 'Atlas', 'Declan', 'Henry' } NOTE: Because sets are unordered, the order in which the names in male_names appear may differ from above.

Respuesta :

Answer:

The code is given below in Python with appropriate comments

Explanation:

# convert list to set

male_names = set(['Oliver','Declan','Henry'])

# get remove and add name from user

remove_name = input("Enter remove name: ")

add_name = input("Enter add name: ")

# remove name from set

male_names.remove(remove_name)

# add new name ij set

male_names.add(add_name)

# sort the set

a = sorted(male_names)

# print the set

print(a)

fichoh

The program which performs the stated instruction is written in python 3 thus ;

pop_names = set(['Oliver', 'Declan', 'Henry'])

#set of popular names

rem_name = input('Enter name to remove : ')

#input for name to remove

add_name = input("Enter name to add : ")

#replacement for removed name

pop_names.remove(rem_name)

pop_names.add(add_name)

print(pop_names)

#display the names.

A sample run of the program is attached.

Learn more : https://brainly.com/question/12483071

Ver imagen fichoh