Discover the best answers at Westonci.ca, where experts share their insights and knowledge with you. Discover in-depth answers to your questions from a wide network of experts on our user-friendly Q&A platform. Discover detailed answers to your questions from a wide network of experts on our comprehensive Q&A platform.

CHALLENGE ACTIVITY
1.6.1: Type casting: Computing average owls per zoo.
Assign avg_owls with the average owls per zoo. Print avg_owls as an integer.

Sample output for inputs: 1 2 4
Average owls per zoo: 2

-------------------------------------------------------------------
Someone please explain what I am doing wrong?


CHALLENGE ACTIVITY161 Type Casting Computing Average Owls Per ZooAssign Avgowls With The Average Owls Per Zoo Print Avgowls As An IntegerSample Output For Input class=

Sagot :

Answer:

avg_owls=0.0

num_owls_zooA = int(input())

num_owls_zooB = int(input())

num_owls_zooC = int(input())

num_zoos = 3

avg_owls = (num_owls_zooA + num_owls_zooB + num_owls_zooC) / num_zoos

print('Average owls per zoo:', int(avg_owls))

Explanation:

There is a problem while you are trying the calculate the average owls per zoo.

As you may know, in order to calculate the average, you need to get the total number of owls in all the zoos, then divide it to the number of zoos. That is why you need to sum num_owls_zooA + num_owls_zooB + num_owls_zooC and divide the result by num_zoos

Be aware that the average is printed as integer value. That is why you need to cast the avg_owls to an int as int(avg_owls)