Python Forum
I am having trouble understanding homework.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I am having trouble understanding homework.
#1
Hello, I am currently stuck on a homework lab for zybooks and I am clueless as to what I am supposed to add to my code to make it work.
Prompt:
The top 3 most popular male names of 2017 are Oliver, Declan, and Henry according to babynames.com.

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.

My code so far:
male_names = { 'Oliver', 'Declan', 'Henry' }
name_to_remove = input()
name_to_add = input()

''' Your solution goes here '''
male_names.remove('Oliver')
male_names.add('Atlas')

print(male_names)
I tried to remove the first name, and add a new one so far but I notice the expected output prints the names in a different order, some hints in the right direction would help.

Output:
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' }
buran write Feb-17-2021, 09:35 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
I am having trouble understanding homework. - by theyhateadam - Feb-17-2021, 01:09 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020