V
V
veronikakravchenko2018-04-07 15:39:37
Python
veronikakravchenko, 2018-04-07 15:39:37

How to replace numbers in a Python worksheet?

In a list of integers with 19 elements, determine the maximum number and replace all even elements with it.
The numbers are given by random values ​​from -100 to 100

myList = []
import random as rd
a = 0
while a<19:
    myList.append(rd.randint(-100,100))
    a += 1
print(myList)

max(myList)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly, 2018-04-07
@veronikakravchenko

m = max(myList)
for i in range(0, len(myList), 2):
    myList[i] = m

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question