196k views
2 votes
A loop that will output every other name in the names list.

A loop that will output only the positive numbers in the numbers list.
A loop that will output the sum of all the values in the numbers list.
A loop that will output only the numbers that are odd.
A loop that will output only the names that come before "Thor" in the alphabet from the names list.
A loop that will find the maximum or minimum value in the numbers list. This algorithm requires an additional variable that is assigned to the first element in the list. Then, in a loop compare each element to the variable. If the element is > (for max) or < (for min), assign the variable to the element. After the loop, print the variable.
in python
PLEASE HELPPPP

User Zoonosis
by
5.6k points

1 Answer

6 votes

Answer:

names = ['Peter', 'Bruce', 'Steve', 'Tony', 'Natasha', 'Clint', 'Wanda', 'Hope', 'Danny', 'Carol']

numbers = [100, 50, 10, 1, 2, 7, 11, 17, 53, -8, -4, -9, -72, -64, -80]

for index, element in enumerate(names):

if index % 2 == 0:

print(element)

for num in numbers:

if num >= 0:

print(num, end = " ")

count = 0

for i in numbers:

count += i

avg = count/len(numbers)

print("sum = ", count)

print("average = ", avg)

for num in numbers:

if num % 2 != 0:

print(num, end = " ")

Step-by-step explanation:

I'm stuck on the last two.. I have to do those too for an assignment.

User Lukegravitt
by
5.9k points