Python Forum
Python Homework Question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Homework Question
#1
Can someone help me with my python homework I have been stuck on it for days now?

Write a program that filters different chemical compounds from a list of elements. The first input line will contain the atomic numbers of different elements separated by comma and space (", "). On the next several lines you will be given indices of elements that form a single compound separated by a dash
("-"). You have to validate the indices:
- If the index is out of range print: "Invalid indices" and ignore the line
- If any of the indices is already included in another compound print: "Index {index} already taken" and ignore the line
- If all the indices are valid/free print the formed compound in the format: "Found compound: {compound_list}"
When you receive the command "end", stop the program and print the following:
Total compounds: {total_found_compounds}
Elements left: {list_remaining_elements}
Input
On the first line you will receive a list of the elements
Until the command "end" you will get indices that form a compound
Output
Print the output as described above



Examples
Input Output
1, 1, 8, 11, 17, 8, 11, 1, 6, 8, 8, 8
0-7-2
3-4-10
6-1-8-5-9-11
end Found compound: [1, 1, 8]
Found compound: [11, 17, 8]
Found compound: [11, 1, 6, 8, 8, 8]
Total compounds: 3
Elements left: []
11, 1, 8, 17, 16, 17, 8, 1
0-5
1-5
20-2
5-2
end Found compound: [11, 17]
Index 5 already taken
Invalid indices
Index 5 already taken
Total compounds: 1
Elements left: [1, 8, 17, 16, 8, 1]
Reply
#2
We are glad to help, but we are not going to do your homework for you. Post your best attempt at solving this task. Post your code in python tags, full traceback uf you get any - in error tags and ask specific questions.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  HELP in python homework makashito 4 3,864 Oct-12-2021, 10:12 AM
Last Post: buran
  CyperSecurity Using Python HomeWork ward1995 1 1,931 Jul-08-2021, 03:55 PM
Last Post: buran
Exclamation urgent , Python homework alm 2 2,257 May-09-2021, 11:19 AM
Last Post: Yoriz
  Homework with python Johnsonmfw 1 1,660 Sep-20-2020, 04:03 AM
Last Post: ndc85430
  Homework help:While Loops question Midhat_School 6 3,024 Jul-26-2020, 10:23 AM
Last Post: pyzyx3qwerty
  IF ELSE Homework Question buckthimble 1 2,110 Mar-29-2020, 06:29 AM
Last Post: buran
  Python Homework Help *Urgent GS31 2 2,539 Nov-24-2019, 01:41 PM
Last Post: ichabod801
  Python homework / functions sunhyunshine 1 2,416 May-11-2019, 05:37 PM
Last Post: MrTheOne
  Homework question dmhhfm 4 13,291 Apr-10-2019, 07:22 AM
Last Post: DeaD_EyE
  python homework help ASAP gk34332 1 2,944 Mar-13-2019, 07:27 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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