Last active
September 19, 2016 17:24
-
-
Save Spotik/a6b80b0e931cfecf00b76a8ed5e90870 to your computer and use it in GitHub Desktop.
https://repl.it/Da12/0 created by Spotik
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''Altere o programa anterior de modo a exibir a posição em que o valor X está na lista. Se houver mais de uma | |
ocorrência de X na lista, todas as posições devem ser exibidas.''' | |
from random import randint | |
numeros = input("Informa a quantidade de números que serão gerados: ") | |
lista = [] | |
count = 0 | |
while count < numeros: | |
n = randint(0,1000) | |
lista.append(n) | |
count += 1 | |
print lista | |
x = input("Informe número deseja saber se está na lista: ") | |
if lista.count(x) > 0: | |
count = 0 | |
posicoes = [] | |
while count < len(lista): | |
if lista[count] == x: | |
posicoes.append(count) | |
count += 1 | |
print "O número %d está na lista" % x | |
print "Nas posições: " + str(posicoes) | |
else: | |
print "O número %d não está na lista" % x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment