Creating and modifying sets.
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.
1 male_names = { 'oliver', 'Declan', 'Henry' }
2 name_to_remove = input()
3 name_to_add = input()
4 male_names = { 'oliver', 'Declan', 'Henry' }
5
6 #The statement to remove 'oliver' from the set.
7
8 male_names.remove('oliver')
9
10 #Add the name 'Atlas' in the set ,ale_names.
11
12 male_names.add('Atlas')
13
14 print(male_names)
Testing with inputs: 'Oliver''Atlas'
Your output { 'Atlas', 'Declan', 'Henry' }
Testing with inputs: 'Declan' 'Noah'
Output differs. See highlights below.
Your output { 'Atlas', 'Declan', 'Henry' }
Expected output { 'Henry', 'Noah', 'Oliver' }

Respuesta :

Answer:

Explanation:

The following Python code asks the user for inputs for the name to remove and add in the set. It then tries to remove the given name from the list. If it fails it prints out to the user saying that the name does not exist. If it does exist then it removes the name and adds the new name. Finally it prints out the current list of names.

male_names = {'oliver', 'Declan', 'Henry'}

name_to_remove = input("Enter name to remove: ")

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

try:

   male_names.remove(name_to_remove)

   male_names.add(name_to_add)

except:

   print("Name that you are trying to remove does not exist")

print("List of Names: ")

print(male_names)

Ver imagen sandlee09

In this exercise we have to use the knowledge of the python language to write the code, so we have to:

The code is in the attached photo.

So to make it easier the code can be found at:

male_names = {'oliver', 'Declan', 'Henry'}

name_to_remove = input("Enter name to remove: ")

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

try:

  male_names.remove(name_to_remove)

  male_names.add(name_to_add)

except:

  print("Name that you are trying to remove does not exist")

print("List of Names: ")

print(male_names)

See more about python at brainly.com/question/26104476

Ver imagen lhmarianateixeira