88.2k views
4 votes
Design a program that uses a loop to build a list named valid_numbers that contains only the numbers between 0 and 100 from the numbers list below. The program should then determine and display the total and average of the values in the valid_numbers list.

User Joseph Bui
by
7.5k points

2 Answers

1 vote

Answer:74,19,105,20,-2,67,77,124,-45,38

Explanation:break it down

User Ndogac
by
6.7k points
6 votes

Final answer:

To design a program that uses a loop to build a list named valid_numbers containing only the numbers between 0 and 100 from a given list, you can use a simple Python code.

Step-by-step explanation:

To design a program that uses a loop to build a list named valid_numbers containing only the numbers between 0 and 100 from a given list, you can use the following Python code:

numbers = [94, 43, 36, 60, 103, 27, 79, 88, 101, 55, 101]
valid_numbers = []

for num in numbers:
if num >= 0 and num <= 100:
valid_numbers.append(num)

total = sum(valid_numbers)
average = total / len(valid_numbers)

print('Total:', total)
print('Average:', average)

This code defines the 'numbers' list and initializes an empty 'valid_numbers' list. It then iterates through each number in the 'numbers' list and checks if it falls between 0 and 100. If it does, it appends it to the 'valid_numbers' list. Finally, it calculates the total and average of the values in the 'valid_numbers' list and prints them.

User Sarah M Giles
by
7.9k points