In class, we were handed a sheet with a bunch of tasks that are to be completed as a practice for our upcoming coursework. For one of the tasks, we needed to create a program that has girl shoe sizes in a list, and the program would need to add the sum of the shoe sizes, and add the total to the beginning of the list, and then create another list that counts how many of the shoe sizes there are.
Then we need to create the same code for boy shoe sizes, and in the end compare the sums of each list.
So, in the beginning, we would need to create an empty list called "girl_shoes", and on a separate line, we add the contents of the list using the method ".extend()". Since we need the sum of the shoe sizes added to the beginning of the list, we create a variable, "total_girls" that holds the value of the sum of the shoes, and use the "sum" method to add the contents of our list (considering they are integers) together. For this part, I get slightly confused as its an unfamiliar approach, but its a simple one. To actually add the sum to the beginning of the "girl_shoes" list, we use the ".insert()" method. As seen in the code, I wrote it like this :
"girl_shoes.insert (0,total_girls)". Now, its clear that "girl_shoes" is the name of the list that the ".insert()" method is being applied to, however, in the parenthesis, you need to mention the index that you want your content to be added at, and to what variable or list. So in this case, I wrote : "(0,total_girls)", "0" being the index I want it to be inserted at, and "total_girls" the variable that referred to the list I wanted to add it to.
And now we add the sum to our list, and print it.
The next step would be to count how many of the shoe sizes there were. To do this, we would need to use the ".count()". However since it was needed for every shoe size, we would need to create a variable for each shoe size, and then apply the ".count()" method. Then all that's left is to call on each method for each shoe size, and compare the sum of the contents of each list using the following if and else statements as seen below:
The final result should be:
Hope this could be of use later on. :3