24.5k views
4 votes
The following program includes fictional sets of the top 10 male and female baby names for the current year. Write a program that creates: A set all_names that contains all of the top 10 male and all of the top 10 female names. A set neutral_names that contains only names found in both male_names and female_names. A set specific_names that contains only gender specific names. Sample output for all_names: {'Michael', 'Henry', 'Jayden', 'Bailey', 'Lucas', 'Chuck', 'Aiden', 'Khloe', 'Elizabeth', 'Maria', 'Veronica', 'Meghan', 'John', 'Samuel', 'Britney', 'Charlie', 'Kim'} NOTE: Because sets are unordered, they are printed using the sorted() function here for comparison.

User Gerry P
by
5.7k points

2 Answers

0 votes

Answer:

Answer code is given below and explained step by step with comments. Output is given at the end of code as well as attached as an image. Happy Learning!

Step-by-step explanation:

Code:

Male_Names ={'Michael','Henry','Jayden','Bailey','Lucas','Chuck','Aiden',' John','Samuel','Charlie'} # array to store Male Names

Female_Names= {'Khloe','Elizabeth','Maria','Veronica','Meghan','Britney', 'Kim','Bailey', 'Jayden', 'Aiden'} # array to store Female Names

All_Names = Male_Names.union(Female_Names) # the union will return all the names found in Male_Names + Female_Names and if there are any duplicate names then they will appear only once

Neutral_Names = Male_Names.intersection(Female_Names) # the intersection will return only those names which are common in both Male_Names and Female_Names hence they will be neutral names

Specific_Names = Male_Names.symmetric_difference(Female_Names) # the symmetric_difference will return only those names which are not common in Male_Names and Female_Names hence they will be Male Names and Female Names

print(All_Names) # to print all the names

print(Neutral_Names) # to print neutral names

print(Specific_Names) # to print specific names

print(sorted(All_Names)) # to print all the names in ascending order

print(sorted(Neutral_Names)) # to print neutral names in ascending order

print(sorted(Specific_Names)) # to print specific names in ascending order

Notice that male and female names are 10 each

In both of these lists 3 names are common

so there are 7 unique male names and 7 unique female names

All_Names must return 7 unique male names, 7 unique females names and 3 common names = 7+7+3= 17 names

Neutral_Names must return 3 common names

Specific_Names must return 7 male males and 7 female names

7+7= 14 names

OUTPUT:

Unsorted:

{'Henry', 'Bailey', 'Elizabeth', 'John', 'Chuck', 'Britney', 'Lucas', 'Khloe', 'Charlie', 'Aiden', 'Jayden', 'Kim', 'Samuel', 'Maria', 'Michael', 'Veronica', 'Meghan'}

{'Bailey', 'Jayden', 'Aiden'}

{'Henry', 'Elizabeth', 'John', 'Chuck', 'Britney', 'Lucas', 'Khloe', 'Kim', 'Maria', 'Veronica', 'Charlie', 'Samuel', 'Michael', 'Meghan'}

Sorted:

{'Aiden', 'Bailey', 'Britney', 'Charlie', 'Chuck', 'Elizabeth', 'Henry', 'Jayden', 'John', 'Khloe', 'Kim', 'Lucas', 'Maria', 'Meghan', 'Michael', 'Samuel', 'Veronica'}

{'Aiden', 'Bailey', 'Jayden'}

{'Britney', 'Charlie', 'Chuck', 'Elizabeth', 'Henry', 'John', 'Khloe', 'Kim', 'Lucas', 'Maria', 'Meghan', 'Michael', 'Samuel', 'Veronica'}

The following program includes fictional sets of the top 10 male and female baby names-example-1
User Jdaz
by
5.4k points
6 votes

Answer:

The code has been added and explained appropriate comments. The output of the code is indicated in the multi-line comments below

Step-by-step explanation:

male_names = {'John', 'Bailey', 'Charlie', 'Chuck', 'Michael', 'Samuel', 'Jayden', 'Aiden', 'Henry', 'Lucas'}

female_names = {'Elizabeth', 'Meghan', 'Kim', 'khloe', 'Baile', 'Jayden', 'Aiden', 'Britney', 'Veronica', 'Maria'}

all_names = male_names | female_names # UNION

neutral_names = male_names & female_names # INTERSECTION

specific_names = (male_names - female_names) | (female_names - male_names) # DIFFERENCE

print(all_names)

print(neutral_names)

print(specific_names)

''' OUTPUT

{'Henry', 'Charlie', 'khloe', 'Samuel', 'Aiden', 'Michael', 'Meghan', 'Lucas', 'Maria', 'John', 'Britney', 'Veronica', 'Chuck', 'Elizabeth', 'Bailey', 'Kim', 'Jayden', 'Baile'}

{'Aiden', 'Jayden'}

{'Henry', 'Charlie', 'khloe', 'Samuel', 'Michael', 'Meghan', 'Lucas', 'Maria', 'John', 'Britney', 'Veronica', 'Chuck', 'Elizabeth', 'Bailey', 'Kim', 'Baile'}

'''

User Dcolazin
by
5.6k points