Python Forum
Python Homework Question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Python Homework Question (/thread-20819.html)



Python Homework Question - OrcDroid123 - Sep-01-2019

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]


RE: Python Homework Question - buran - Sep-01-2019

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.