Computer Science, asked by avanthikaavi9474, 1 year ago

A teacher is conducting a camp for a group of five children. Based on their performance and behavior during the camp, the teacher rewards them with chocolates. Write a python function to find the total number of chocolates received by all the children put together. Assume that each child is identified by an id and it is stored in a tuple and the number of chocolates given to each child is stored in a list. The teacher also rewards a child with few extra chocolates for his/her best conduct during the camp. If the number of extra chocolates is less than 1, an error message "extra chocolates is less than 1", should be displayed. If the given child id is invalid, an error message "child id is invalid" should be displayed. Otherwise, the extra chocolates provided for the child must be added to his/her existing number of chocolates and display the list containing the total number of chocolates received by each child.

Answers

Answered by nitika55
4
What we have to do in this
Answered by surajnegi0600
0

Answer:

Here is a Python function that implements the described behavior:

def reward_children(child_ids, chocolates, child_id, extra_chocolates):

   if extra_chocolates < 1:

       print("extra chocolates is less than 1")

       return

   if child_id not in child_ids:

       print("child id is invalid")

       return

   index = child_ids.index(child_id)

   chocolates[index] += extra_chocolates

   print(chocolates)

   total_chocolates = sum(chocolates)

   return total_chocolates

Explanation:

You can test the function with the following code:

child_ids = (1, 2, 3, 4, 5)

chocolates = [10, 15, 20, 25, 30]

child_id = 3

extra_chocolates = 5

print(reward_children(child_ids, chocolates, child_id, extra_chocolates))

It will output the chocolates list with extra chocolates added to the specified child, and the total number of chocolates received by all the children.

More questions and answers

https://brainly.in/question/50334736

https://brainly.in/question/50192228

#SPJ3

Similar questions