They ask me the following:
Perform an algorithm that generates 100 random numbers from 1 to 200. The system must save these random numbers in a range of 100 positions, in this arrangement you should not repeat any number generated. After filling the arrangement with the 100 numbers, make the sum of the odd and even numbers and according to the result, show the message which was greater (the sum of the pairs or the sum of the odd ones), in case that the result is equal, show the two results of the sums.
The theme is functions and arrangements, so I started like this:
from random import randrange
from time import sleep
numeros = []
validacion = []
longitudx = 10
longitudy = 10
def lista():
numeros.append([])
def imprimir_numeros():
longitud = len(numeros)
for i in range(longitud):
print(numeros[i])
def validacion(numero):
for i in range(longitudx):
for j in range (longitudy):
if numeros[i][j] == numero :
return False
break
return numero
numeros = randrange(200)
def llenar_numeros():
x = 0
while x < longitudx:
y = 0
while y < longitudy:
numero = validacion(randrange(200))
if numero:
numeros[x][y] = numero
y += 1
imprimir_numeros()
print(" ")
print(" ")
x += 1
def sumatoria():
for numero in numeros:
if numero // 2 == 0:
suma_pares = numero
print(" La suma de los numeros pares es " + str(suma_pares) )
elif numero // 2 !=0:
suma_impares = numero
print(" La suma de los impares es " + str(suma_impares))
llenar_numeros()
sumatoria()
At the time of running it gives me several errors, I need help to fill the list with the numbers and then I identify the odd and even and then make the sum of them.