Task 1 Task 2 Task 3
Task 1 Task 2 Task 3

Suggested Solution

def generateAverage(x):

total = 0

for i = range(x):

total = total + random.randint(1, 100)

average = total/x

print(f"The average value of {x} random numbers between 1 and 100 is {average}")

#call the function

num = int(input("How many numbers: "))

generateAverage(num)

Random Name

Task 1

A function generateAverage(x) generates x random numbers between 1 and 100.

It displays the average value.

Design this function and test it by calling it.

Random Name

Task 2

A kindergarten teacher is teaching animal words to her students. She is trying to explain that words have different lengths.

Write a program that will allow the teacher to enter 5 different animal names. It will show the length of each word, and at the end, the total length of all of the words and a count of all words with a length greater than 6.

Test your program with the following words:

catrabbitelephantcrocodilered-lipped batfish

The final total should be 44 and the count should be 3.

Modularise your solution. Think about what functions are required. Which functions process parameters? Do we need any global variables?

Task 3

A computer program generates 10 random numbers in the range 1 to 10.

If each pair of numbers adds up to a number greater than 10, the first number is added to a total.

For example, if the following 10 numbers are generated:

3811348521

then the program will produce a total of 11.

Write this program.

Modularise your solution. Think about what functions are required. Which functions process parameters? Do we need any global variables?