Created
October 16, 2018 19:22
-
-
Save MariiMartins/d9b192533f5bffdc1c62c126449e59a6 to your computer and use it in GitHub Desktop.
Lista - Laço de Repetição
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
# Imprimir os multiplos de 5, no intervalo de 1 até 500. | |
for multi in range (5,505,5): | |
print (multi) |
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
# Desenvolver um algoritmo que exiba o resultado do fatorial de um número inteiro informado pelo usuário. | |
num = int (input("Digite um número: ")) | |
fat = 1 | |
for i in range (1, num+1): | |
fat *= i | |
print (fat) |
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
# Desenvolver um algoritmo que exiba os números ímpares de 1 ate 100. | |
for i in range (1, 100, 2): | |
print(i) | |
# | |
n_imp = 1 | |
while (n_imp < 100): | |
print(n_imp) | |
n_imp += 2 |
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
# Obtenha o espelho de um valor inteiro positivo. | |
num = str(input("Digite um numero: ")) | |
k = len(num) | |
num = int(num) | |
novo_num = 0 | |
while num != 0: | |
novo_num += (num % 10) * 10**(k-1) | |
num //= 10 | |
k -= 1 | |
print (novo_num) |
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
# Obter o máximo divisor comum de dois valores inteiros | |
a = int(input("Digite um valor maior que zero ")) | |
b = int(input("Digite outro valor maior que zero ")) | |
mdc = a | |
while a % mdc != 0 or b % mdc != 0: | |
mdc = mdc - 1 | |
print("O MDC entre %d,%d (%d)" %(a,b,mdc)) | |
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
# Foi realizada uma pesquisa entre os hanitantes de uma dada região. Foram recolhidos os dados de idade, sexo e salario. Construa um algoritmo que informe: | |
# Media Salario; maior e menor idade; qnt mulheres salraio até 500 | |
idade = 0 | |
sexo = "F" | |
salario = 0.0 | |
qtdeMulheresSalario = 0 | |
somaSalario = 0 | |
contador = 0 | |
mediaSalarial = 0.0 | |
menorIdade = 999 | |
maiorIdade = 0 | |
while(1==1): | |
sexo = input("Entre com o sexo") | |
idade = int(input("Entre com a idade")) | |
salario = float(input("Entre com o salario")) | |
#sai do loop se idade negativa | |
if(idade < 0): | |
break | |
if(sexo == "F" and salario < 500): | |
qtdeMulheresSalario += 1 | |
somaSalario = somaSalario + salario | |
if(idade < menorIdade): | |
menorIdade = idade | |
if(idade > maiorIdade): | |
maiorIdade = idade | |
contador += 1 | |
if(contador > 0): | |
mediaSalarial = somaSalario / contador | |
print(mediaSalarial) | |
print(qtdeMulheresSalario) | |
print(menorIdade) | |
print(maiorIdade) |
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
#Desenvolver um algoritmo que exiba os números pares de 1 a 400. | |
n_pares = 2 | |
while (n_pares < 402): | |
print(n_pares) | |
n_pares += 2 | |
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
# Imprimir o quadrado dos números de 1 até 20 | |
n = 0 | |
while (n < 20): | |
print(n**2) | |
n += 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
# Ler um número maior que zero e imprimir o quadrado de todos os números entre 0 e o número lido. | |
a = int (input ("Digite um numero maior que zero ")) | |
n = 0 | |
while (n <= a): | |
print(n**2) | |
n += 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
# Ler um número maior que 0 e imprimir a soma de todos os números menores que o número lido. | |
num = int(input("Digite um numero maior que 0: ")) | |
count = 0 | |
for i in range(0, num): | |
count += i | |
print (count) |
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
# Ler dois numeros e imprimir todos os numeros entre eles. Suponha que o segundo numero seja maior que o primeiro. | |
n1 = int (input("Digite o numero 1")) | |
n2 = int (input ("Digite o numero 2")) | |
for i in range (n1,n2): | |
print (i) |
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
# Ler um número inteiro e imprimir todos os números primos de 1 até o número informado. | |
num = int (input ("Digite um numero")) | |
for i in range (1,num+1): | |
ePrimo = True | |
for j in range (2, i): | |
if i%j == 0: | |
ePrimo = False | |
if ePrimo: | |
print (i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment