Solved:

Checkmark

Answered by AI, Verified by Human Experts

Creating and modifying sets.

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' }

In this exercise we have to use the knowledge of thepython languageto write thecode, so we have to:The code is in the attached photo.So to make it easier thecodecan 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 aboutpythonatbrainly.com/question/26104476...

Unlock full access for 72 hours, watch your grades skyrocket.
For just $0.99 cents, get access to the powerful quizwhiz chrome extension that automatically solves your homework using AI. Subscription renews at $5.99/week.