Escolar Documentos
Profissional Documentos
Cultura Documentos
Python
Python
Exercício 9 – Tabuada
import pygame
pygame.mixer.init()
pygame.init()
pygame.mixer.music.load('e.mp3')
pygame.mixer_music.play()
pygame.event.wait()
print('-=-' * 20)
print('Analisando um triângulo')
print('-=-' * 20)
a = int(input('Primeiro segmento: '))
b = int(input('Segundo segmento: '))
c = int(input('Terceiro segmento: '))
if a < b + c and b < a + c and c < a + b:
print('Os segmentos acima PODEM FORMAR UM TRIÂNGULO!')
else:
print('Os segmentos acima NÃO FORMAM UM TRIÂNGULO!')
s=0
cont = 0
for c in range(1, 501, 2):
if c % 3 == 0:
cont += 1
s += c
print('''A soma de todos os {} múltiplos de 3
de 0 à 500 é {}'''.format(cont, s))
s=0
cont = 0
for c in range(1, 7):
n = int(input('Digite o {} valor: '.format(c)))
if n % 2 == 0:
s += n
cont += 1
print('Vc informou {} números pares e a soma é {}'.format(cont, s))
Primeiro termo: 5
Razao: 2
Quantos elementos exibir: 3
5 -> 7 -> 9 ->
n = cont = soma = 0
while True:
n = int(input('Digite um valor (999 para parar): '))
if n == 999:
break
cont += 1
soma += n
print(f'Foram digitados {cont} números e a soma entre eles é {soma}.')
while True:
número = int(input('Quer ver a tabuada de qual valor? '))
if número < 0:
break
print('=' * 35)
for c in range(1, 11):
print(f'{número} x {c} = {número * c}')
print('=' * 35)
print('PROGRAMA TABUADA ENCERADO.')
print('=' * 30)
print('{:^30}'.format('PRODUTOS'))
print('=' * 30)
soma = contm = menor = cont = 0
barato = ' '
while True:
produto = str(input('Nome do Produto: '))
preço = float(input('Preço: R$ '))
soma += preço
cont += 1
if preço > 1000:
contm += 1
if cont == 1: #SE FOR O PRIMEIRO PRODUTO
menor = preço
barato = produto
else:
if preço < menor:
menor = preço
barato = produto
resp = ' '
while resp not in 'SN':
resp = str(input('Quer continuar? [S/N]')).strip().upper()[0]
if resp == 'N':
break
print(f'O total da compra foi: R$ {soma:.2f}')
print(f'Temos {contm} produtos custando mais de R$1000.00')
print(f'O produto mais barato foi {produto} que custa {menor:.2f}')
print('=' * 40)
print('{:^40}'.format('BANCO'))
print('=' * 40)
num = int(input('Que valor você quer sacar? R$ '))
total = num
ced = 50
totced = 0
while True:
if total >= ced:
total -= ced
totced += 1
else:
if totced > 0:
print(f'Total de {totced} cédulas de R${ced}')
if ced == 50:
ced = 20
elif ced == 20:
ced = 10
elif ced == 10:
ced = 1
totced = 0
if total == 0:
break
print('=' * 40)
print('{:^40}'.format('VOLTE SEMPRE!'))
print('=' * 40)
L = []
for c in range(0, 5):
L.append(int(input(f'Digite um valor para a Posição {c}: ')))
#print(f'O maior valor digitado foi o {max(L)} nas posições {[L.index(max(L))]}...')
#print(f'O menor valor digitado foi o {min(L)} nas posições {[L.index(min(L))]}...')
if c == 0:
mai = men = L[c]
else:
if L[c] > mai:
mai = L[c]
if L[c] < men:
men = L[c]
print(f'Você digitou os valores {L}')
print(f'O maior valor digitado foi {mai} nas posições', end=' ')
for i, v in enumerate(L):
if v == mai:
print(f'{i}...', end=' ')
print()
print(f'O menor valor digitado foi {men} nas posições', end=' ')
for i, v in enumerate(L):
if v == men:
print(f'{i}...', end=' ')
L = []
while True:
n = (int(input('Digite um valor: ')))
if n not in L:
L.append(n)
print('valor Add com sucesso....')
else:
print('Valor duplicado!Não vou add...')
tipo = ' '
while tipo not in '[S/N]':
tipo = str(input('Quer continuar? [S/N] ')).strip().upper()[0]
if tipo == 'N':
break
print('-=' * 30)
L = []
for c in range(0, 5):
n = (int(input(f'Digite um valor: ')))
if c == 0 or n > L[len(L)-1]: #SE O NUMERO FOR MAIOR QUE O NUMERO QUE ESTÁ NO ULTIMO
ELEMENTO
L.append(n)
print('Add ao final da lista')
else:
pos = 0
while pos < len(L):
if n <= L[pos]:
L.insert(pos, n)
print(f'Add na posição {pos} da lista')
break
pos += 1
print(f'Os valores digitados foram {L}')
L = []
while True:
L.append(int(input('Digite um valor: ')))
tipo = ' '
while tipo not in '[S/N]':
tipo = str(input('Quer continuar? [S/N] ')).strip().upper()[0]
if tipo == 'N':
break
L.sort(reverse=True)
print(f'Você digitou {len(L)} elementos')
print(f'Os valores em ordem decrescente são {L}')
if 5 in L:
print('O valor 5 faz parte da lista')
else:
print('O valor 5 não faz parte da lista')
L = []
while True:
L.append(int(input('Digite um valor: ')))
P = []
I = []
for e in L:
if e % 2 == 0:
P.append(e)
else:
I.append(e)
tipo = ' '
while tipo not in '[S/N]':
tipo = str(input('Quer continuar? [S/N] ')).strip().upper()[0]
if tipo == 'N':
break
print(f'A lista completa é {L}')
print(f'A lista de pares é {P}')
print(f'A lista de impares é {I}')