Created
September 22, 2016 18:42
-
-
Save Spotik/8eca755534509dc0ab919e3fa56da3fa to your computer and use it in GitHub Desktop.
lista2_ex10 created by Spotik - https://repl.it/DfbP/1
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