
Suppose you have decided to collect some statistics on the squirrels in your neighborhood and require a computer program to calculate these statistics. Create a program that allows the user to enter the length and weight of squirrels, and calculates the average weight and average length of all the squirrels entered. The program should output the average weight and average length after each squirrel is entered. Use two functions for the program:
Both these functions will make use of global variables. You will need three global variables: the total length, the total weight, and the number of squirrels entered so far. Use descriptive variable names. Once the functions are defined and the global variables created, you will be able to use a loop like this in the main part of the program:
while True: enter_squirrel() display_stats()
To allow the user to stop, you can use this permutation:
while True:
enter_squirrel()
display_stats()
if('n' == input("Enter another squirrel? (y/n) ").lower()):
break