1
from random import randint # para gerar os nums aleatorios
def criaVetor(L, H, tam):
vec = []
for i in range(tam): # vamos fazer isto tam (N) vezes
vec.append(randint(L, H)) # gerar numero aleatorio entre L e H, e colocar na nossa lista
return vec
def pegaExtremosUnicos(vec):
i = 1
for i in range(len(vec)):
atual = vec[i]
j = i - 1;
while (j >=0) and (atual < vec[j]):
vec[j +1] = vec[j]
j = j -1
vec[j + 1] = atual
i = 1
while i < len(vec):
if vec[i] == vec[i-1]:
del vec[i]
del vec[i-1]
i = i +1
d = [vec[0],vec[len(vec)-1]]
return tuple(d)
vec = []
L = int(input('Informe o valor inteiro minimo da faixa:'))
H = int(input('Informe o valor inteiro maximo da faixa:'))
tam = int(input('Informe a quantidade de valores a serem sorteados:'))
print(criaVetor(L, H, tam))
print (pegaExtremosUnicos(criaVetor(L, H, tam)))
What would be wrong?
Where there are no single minimum or maximum values, a tuple of None
's must be returned. For example:
[3, 5, 3, 10, 8]
returns(5, 10)
- return ok[13]
returns(13, 13)
d = [vec[0],vec[Len(vec)-1]] Indexerror: list index out of range[13, 13, 8, 8]
returns(None, None)
Enter the minimum integer value of the range:8 Enter the maximum integer value of the range:13 Enter the amount of values to be drawn:4 [10, 10, 12, 10] (9, 11)
Upon return from the subprogram, the main program must display the tuple produced.
Absoares, you must ask the question that you cannot answer. It is important for those who want to help you to know this. http://answall.com/posts/148249/edit. Welcome to stack overflow
– Miguel
A question: why does it have to be without using the Random function? Whatever way is done here is very extensive complexae, and nor does it approach the effectiveness of this function
– Miguel
@Miguel hum... ok! I’m a beginner ....... Continuing what you did , as would the item (c) .... I got to do something , but this giving error!
– ABSoares
?? I didn’t realize... I put my answer down
– Miguel