Baixe o app para aproveitar ainda mais
Prévia do material em texto
EMB5013 - Introdução à Programação de Computadores Profa. Tatiana Renata Garcia Gabarito Lista 7 - Python 1 - ### Exercicio 1 a = input('digite valor de A: ') b = 0 while a <> b and a > 0: for i in range(1, a+1): j = i while j <= a: print j j = j + 1 b = a a = input('digite valor de A: ') 2 – ### Exercicio 2 a = input('digite valor de a: ') b = input('digite valor de b: ') c = input('digite valor de c: ') d = b**2 - 4*a*c if d >= 0: x1 = (-b + pow(d, 0.5)) / (2.0*a) x2 = (-b - pow(d, 0.5)) / (2.0*a) print x1, x2 else: print 'nao existem raizes reais...' 3 – ### Exercicio 3 a = input('digite valor de a: ') b = input('digite valor de b: ') c = input('digite valor de c: ') if a != b and a!= c and b!= c: if a > b and a > c: if b>c: print a, b, c else: print a, c, b elif b > a and b > c: if a>c: print b, a, c else: print b, c, a elif c> a and c > b: if a > b: print c, a, b else: print c, b, a else: print 'existem numeros iguais....' 4 – ### Exercicio 4 ano = input('digite ano: ') if ano % 400 == 0: print 'ano bissexto' elif (ano % 4 == 0) and (ano % 100 != 0): print 'ano bissexto' else: print 'ano nao bissexto' 5 – ### Exercicio 5 num = input('digite numero: ') if num > 100 and num <= 999: cen = num / 100 aux = num % 100 dez = aux / 10 uni = aux % 10 novo_num = uni * 100 + dez * 10 + cen print novo_num else: print 'numero fora do intervalo...' 6 – ### Exercicio 6 n = input('digite numero:') h = 0 for j in range(1,n+1): h = h + (1 / float(j)) print h 7 – ### Exercicio 7 n = input('digite valor: ') fat = 1 if n > 0: for i in range(1, n+1): fat = fat * i print 'fatorial: ', fat elif n == 0: print 'fatorial: ', fat 8 – ### Exercicio 8 n = input('digite valor: ') if n >= 3: a = 1 b = 1 c = a + b print a print b print c for j in range(4, n+1): a = b b = c c = a + b print c 9 – ### Exercicio 9 import random for i in range(10): x = random.randint(1,50) if i == 0: maior = x menor = x else: if x > maior: maior = x elif x < menor: menor = x print maior, menor 10 – ### Exercicio 10 voto = input('digite voto: ') c1 = 0 c2 = 0 c3 = 0 nulo = 0 branco = 0 while voto != 0: if voto == 1: c1 = c1 + 1 elif voto == 2: c2 = c2 + 1 elif voto == 3: c3 = c3 + 1 elif voto == 4: nulo = nulo + 1 elif voto == 5: branco = branco + 1 else: print 'codigo invalido...' voto = input('digite voto: ') print 'Votos candidatos 1: ', c1 print 'Votos candidatos 2: ', c2 print 'Votos candidatos 3: ', c3 print 'Votos brancos: ', branco print 'Votos nulos: ', nulo 10 – ### Exercicio 10 x = input('digite valor: ') num1 = x / 100 num2 = x % 100 raiz = pow(x, 0.5) if num1 + num2 == raiz: print 'soma igual' else: print 'soma nao igual'
Compartilhar