Funções
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
def fatorial(n): | |
resultado = 1 | |
for i in range(2, n+1): | |
resultado = resultado * i | |
return resultado | |
a = int(input("Digite um número")) | |
print("O fatorial de", a, "é", fatorial(a)) |
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
def ler_nota(txt, minimo, maximo): | |
msg = "Digite " + txt+ " " | |
n = int(input(msg)) | |
while n < minimo or n > maximo: | |
n = int(input(msg)) | |
return n | |
n1 = ler_nota("Nota 1", 0, 100) | |
n2 = ler_nota("Nota 2", 0, 100) | |
media = (n1 *2 + n2 *3)/5 | |
print(media) |
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
def ler_nota(txt = "nota ", minimo=0, maximo=100): | |
msg = "Digite " + txt+ " " | |
n = int(input(msg)) | |
while n < minimo or n > maximo: | |
n = int(input(msg)) | |
return n | |
n1 = ler_nota() | |
n2 = ler_nota("Nota 2", 0, 100) | |
media = (n1 *2 + n2 *3)/5 | |
print(media) |
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
def ler_nota(txt = "nota ", minimo=0, maximo=100): | |
msg = "Digite " + txt+ " " | |
n = int(input(msg)) | |
while n < minimo or n > maximo: | |
n = int(input(msg)) | |
return n | |
n1 = ler_nota(maximo = 10, minimo = 0) | |
n2 = ler_nota("Nota 2", 0, 10) | |
media = (n1 *2 + n2 *3)/5 | |
print(media) |
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
def soma(lista): | |
resultado = 0 | |
for a in lista: | |
resultado = resultado + a | |
return resultado | |
def soma2(*lista): | |
resultado = 0 | |
for a in lista: | |
resultado = resultado + a | |
return resultado | |
def soma3(a, *lista): | |
print(soma([1,3,5,7,9])) | |
print(soma2(1,3,5,7,9)) | |
print(soma3("ok", 1, 2, 3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment