python exercicioc
python exercicioc
#Ex03 - barril
import math as m
volume=0
i=1
resposta = True
while resposta:
altura = float(input("Qual é o valor da altura do barril: "))
circMaior = float(input("Qual é o valor da circunferencia maior: "))
circMenor = float(input("Qual é o valor da circunferencia menor: "))
volume = m.pi*altura*(2*circMaior+circMenor)**2/36
print(" o volume do ",i,".º barril =" ,round(volume,2),"\n")
resposta=(input("\nPretende continuar? s/n"))
if resposta.lower()== "s":
i +=1
else:
resposta = False
#Ex04 - paralelepípedos
areaTotal=0
volume=0
i=1
resposta = True
while resposta:
a = float(input("Qual é o valor da aresta a: "))
b = float(input("Qual é o valor da aresta b: "))
c = float(input("Qual é o valor da aresta c: "))
volume = a*b*c
areaTotal= 2*(a*b+a*c+b*c)
print(" o volume do ",i,".º paralelepípedo =" ,round(volume,2),"\n")
print(" a area total do ",i,".º paralelepípedo =" ,round(areaTotal,2),"\n")
resposta=(input("\nPretende continuar? s/n"))
if resposta.lower()== "s":
i +=1
else:
resposta = False
#Ex05 - triangulos
import math as m
areaTotal=0
p=0
i=1
resposta = True
ladomaior=0
soma=0
while resposta:
i1 = float(input("Qual é o valor do lado 1: "))
ladoMaior=i1
i2 = float(input("Qual é o valor do lado 2: "))
if i2 > ladoMaior:
ladoMaior=i2
soma=i1
else:
soma=i2
i3 = float(input("Qual é o valor do lado 3: "))
if i3 > ladoMaior:
ladoMaior=i3
soma=i1+i2
else:
if soma==i1:
soma=i1+i3
else:
soma=i2+i3
print(" lado maior:",ladoMaior, " soma dos outros:",soma,"\n")
if ladoMaior>soma :
print(" triangulo INVALIDO\n")
else:
p=(i1+i2+i3)/2
areaTotal= m.sqrt(p*(p-i1)*(p-i2)*(p-i3))
print(" a area total do ",i,".º triangulo =" ,round(areaTotal,2),"\n")
while resposta:
a = float(input(" para a 1 equação Qual é o valor do coeficiente a: "))
b = float(input(" para a 1 equação Qual é o valor do coeficiente b: "))
c = float(input(" para a 1 equação Qual é o valor do coeficiente c: "))
d = float(input(" para a 2 equação Qual é o valor do coeficiente d: "))
e = float(input(" para a 2 equação Qual é o valor do coeficiente e: "))
f = float(input(" para a 2 equação Qual é o valor do coeficiente f: "))
delta=(a*e-b*d)
if delta==0:
print(" sistema INVALIDO\n")
else:
x= (c*e-b*f)/delta
y= (a*f -c*d)/delta
print(" a solução do",i," sistema x:" ,round(x,2)," e
y:",round(y,2),"\n")
salarioBase=800
extra=100
perce=0.01
def comissao(nV,tV):
return (nV*extra+tV*perce)
resposta= True
while resposta:
nVendedor=input(' vendedor: ')
nVendas = int(input('quantas vendas: '))
totalVendas=0
for i in range(nVendas):
valorVenda = float(input(f'valor venda {i+1} de {nVendas} :'))
totalVendas=totalVendas+valorVenda
salarioTotal=salarioBase+comissao(nVendas,totalVendas)
print(f'Comissão do vendedor {nVendedor} com salario base {salarioBase} com
{nVendas} carros vendidos num total {totalVendas} -> comissao de
{comissao(nVendas,totalVendas)} e um salario total de {salarioTotal}')
x=input('Continuar? s/n')
while x.lower() !='s' and x.lower()!='n':
x=input('resposta errada! continuar? s/n')
if x.lower() !='s':
resposta=False
salarioHora=100
def comissao(nV,tV):
return (nV*extra+tV*perce)
resposta= True
while resposta:
nFunc=input(' funcionario: ')
nHoras = int(input('quantas horas: '))
if nHoras//40==0:
salarioTotal=salarioHora*nHoras
else:
salarioTotal=salarioHora*40+salarioHora*1.5*(40*(nHoras//40-1)+nHoras%40)
x=input('Continuar? s/n')
while x.lower() !='s' and x.lower()!='n':
x=input('resposta errada! continuar? s/n')
if x.lower() !='s':
resposta=False
return bonus
resposta= True
while resposta:
nFunc=input(' numero funcionario: ')
nomeFunc=input('nome funcionario: ')
salarioTotal=salarioBase+bonusCalc(horasExtra,horasFaltas)
x=input('Continuar? s/n')
while x.lower() !='s' and x.lower()!='n':
x=input('resposta errada! continuar? s/n')
if x.lower() !='s':
resposta=False
nAprovados=0
nDefesa=0
nReprovados=0
n=0
resposta= True
while resposta and n<=5:
n += 1
nAlunos=int(input(' quantos alunos (>0 e <=50): '))
while nAlunos<=0 or nAlunos>50:
nAlunos=int(input('ERRO! quantos alunos (>0 e <=50): '))
notaAcumulada=0
notaMax=0
notaMin=20
for i in range(nAlunos):
nota=float(input(f' Nota do aluno nº{i+1} <: (>=0 e <=20): '))
while nota <0 or nota>20:
nota=float(input(f' Nota do aluno nº{i+1} <: (>=0 e <=20): '))
notaAcumulada += nota
if nota>notaMax:
notaMax=nota
if nota<notaMin:
notaMin=nota
if nota<9.5:
nReprovados += 1
elif nota <=15.5:
nAprovados += 1
else:
nDefesa += 1
aprovados = nAprovados+nDefesa
mediaTurma=notaAcumulada/nAlunos
print(f'dos {nAlunos} da turma {n} com média de {round(mediaTurma,0)}
valores, {nReprovados} estão reprovados e {aprovados} foram aprovados, {nDefesa}
fazem defesa oral')
print(f'a nota mais alta foi {notaMax} e a nota mais baixa foi {notaMin}')
x=input('Continuar? s/n')
while x.lower() !='s' and x.lower()!='n':
x=input('resposta errada! continuar? s/n')
if x.lower() !='s':
resposta=False
nAprovados=0
nDefesa=0
nReprovados=0
n=0
turma=[]
resposta= True
while resposta and n<=5:
n += 1
nAlunos=int(input(' quantos alunos (>0 e <=50): '))
while nAlunos<=0 or nAlunos>50:
nAlunos=int(input('ERRO! quantos alunos (>0 e <=50): '))
notaAcumulada=0
notaMax=0
notaMin=20
for i in range(nAlunos):
nota=float(input(f' Nota do aluno nº{i+1} <: (>=0 e <=20): '))
while nota <0 or nota>20:
nota=float(input(f' Nota do aluno nº{i+1} <: (>=0 e <=20): '))
notaAcumulada += nota
if nota>notaMax:
notaMax=nota
if nota<notaMin:
notaMin=nota
if nota<9.5:
nReprovados += 1
turma.append([i+1,nota,"Reprovado"])
elif nota <=15.5:
nAprovados += 1
turma.append([i+1,nota,"Aprovado"])
else:
nDefesa += 1
turma.append([i+1,nota,"Aprovado para Defesa Oral"])
aprovados = nAprovados+nDefesa
mediaTurma=notaAcumulada/nAlunos
print(f'dos {nAlunos} da turma {n} com média de {round(mediaTurma,0)}
valores, {nReprovados} estão reprovados e {aprovados} foram aprovados, {nDefesa}
fazem defesa oral')
print(f'a nota mais alta foi {notaMax} e a nota mais baixa foi {notaMin}')
for i in range(82):
print('*',end='')
print()
print('|','Aluno\t','|','NotaFinal','|','Situação',sep='\t')
for i in range(82):
print('*',end='')
print()
for n in range(nAlunos):
for i in range(3):
print("|",turma[n][i],'\t',sep="\t",end='')
print()
for i in range(82):
print('*',end='')
print()
x='q'
while x.lower() !='s' and x.lower()!='n':
x=input('continuar? s/n')
if x.lower() !='s':
resposta=False
percen+=nFilhos*0.05
return percen
resposta= True
while resposta:
#nFunc=input(' numero funcionario: ')
#nomeFunc=input('nome funcionario: ')
idadeFunc=int(input('idade funcionario: '))
while idadeFunc<0:
idadeFunc=int(input('idade >=0 funcionario: '))
salarioTotal=salarioBase+salarioBase*bonusCalc(idadeFunc,anosServivo,numFilhos)
x=input('Continuar? s/n')
while x.lower() !='s' and x.lower()!='n':
x=input('resposta errada! continuar? s/n')
if x.lower() !='s':
resposta=False
#Ex12 - triangulos-2
def EX12():
resposta = True
ladomaior=0
soma=0
somaLados=0
while resposta:
i1 = float(input("Qual é o valor do lado 1: "))
ladoMaior=i1
i2 = float(input("Qual é o valor do lado 2: "))
if i2 > ladoMaior:
ladoMaior=i2
soma=i1
else:
soma=i2
i3 = float(input("Qual é o valor do lado 3: "))
if i3 > ladoMaior:
ladoMaior=i3
soma=i1+i2
else:
if soma==i1:
soma=i1+i3
else:
soma=i2+i3
A=max(i1,i2,i3)
somaLados=i1+i2+i3-A
if A==i1:
B=i2
C=i3
elif A==i2:
B=i1
C=i3
else:
B=i1
C=i2
EX12()
def taxaIva(cilind):
if cilind<1000:
taxa = 0.0
elif cilind <1500:
taxa = 0.1
elif cilind < 2000:
taxa = 0.2
else:
taxa = 0.3
return taxa
resposta= True
while resposta:
valorTotal=valorFab+valorFab*taxaIva(cilindrada)
x=input('Continuar? s/n')
while x.lower() !='s' and x.lower()!='n':
x=input('resposta errada! continuar? s/n')
if x.lower() !='s':
resposta=False
tabela=[[0,"mota",25],[1,"carro
ligueiro",50],[2,"todo-o-terreno",75],[3,"carrinha",70]]
quilometragem=[0.10,0.08,0.05]
def taxaAluguer(ind,dias,kilom):
if kilom<100:
indKm=0
elif kilom<500:
indKm=1
else:
indKm=2
return tabela[ind][2]*dias+kilom*quilometragem[indKm]
resposta= True
while resposta:
existe=False
while not existe:
cod=float(input('codigo do automóvel: '))
#verificar se cod existe
for i in range(len(tabela)):
if cod in tabela[i]:
index=i
existe=True
nDias=0
while nDias<=0:
nDias=int(input('numero de dias >0 : '))
kilometros=0
while kilometros<=0:
kilometros=int(input('numero de kilometros >0 : '))
valorTotal=taxaAluguer(index,nDias,kilometros)
x=input('Continuar? s/n')
while x.lower() !='s' and x.lower()!='n':
x=input('resposta errada! continuar? s/n')
if x.lower() !='s':
resposta=False
resposta= True
while resposta:
n=0
while n<=0 or n>=100:
n=int(input('numero interio <100: '))
x="q"
while x.lower() !='s' and x.lower()!='n':
x=input('continuar? s/n')
if x.lower() !='s':
resposta=False
segundo=0
while segundo<=0 or segundo>=100:
segundo=int(input('segundo numero inteiro <100: '))
if primeiro > segundo:
aux=primeiro
primeiro=segundo
segundo=aux
x='q'
while x.lower() !='s' and x.lower()!='n':
x=input('continuar? s/n')
if x.lower() !='s':
resposta=False
#ex17_contarzeros
resposta= True
while resposta:
count=0
n=0
continuar=True
while continuar:
try:
n=int(input('numero inteiro >=0 (termina com -99): '))
except:
continue
if n==-99:
continuar=False
if n==0:
count+=1
x='q'
while x.lower() !='s' and x.lower()!='n':
x=input('continuar? s/n')
if x.lower() !='s':
resposta=False
resposta= True
i=0
while resposta:
i+=1
print(f'Calculo do salario diario do funcionário {i}:')
n=-1
while n<0 or n>10:
try:
n=int(input('horas de trabalho das 8h00-18h00: '))
except:
continue
hDiurnas=n
n=-1
while (n<0 or n>10) or (hDiurnas==10 and n>5) or (n==10 and hDiurnas>5):
try:
n=int(input('horas de trabalho das 20h00-6h00: '))
except:
continue
hNoturnas=n
diaUtil=True
n='q'
while n.lower()!='s' and n.lower()!='n':
try:
n=input('domingo ou feriado s/n: ')
except:
continue
if n.lower()=='s': diaUtil=False
salarioDiario=hDiurnas*tarifas[0][1]+hNoturnas*tarifas[1][1]
if not diaUtil:
salarioDiario+=hDiurnas*tarifas[2][1]+hNoturnas*tarifas[3][1]
x='q'
while x.lower() !='s' and x.lower()!='n':
x=input('continuar? s/n')
if x.lower() !='s':
resposta=False
segundo=0
while segundo<=0 or segundo>=100:
segundo=int(input('segundo numero inteiro <100: '))
x='q'
while x.lower() !='s' and x.lower()!='n':
x=input('continuar? s/n')
if x.lower() !='s':
resposta=False
#ex20_mediaalunos
media=0
resposta= True
while resposta:
continuar=True
count=1
n=1
soma=0
while continuar:
n=int(input(f'nota do aluno {count} numero inteiro >0 e <=20 (termina
com -99): '))
x='q'
while x.lower() !='s' and x.lower()!='n':
x=input('continuar? s/n')
if x.lower() !='s':
resposta=False
"""22. Desenha um algoritmo que leia uma frase com mais de 10 caracteres e no
fim diga quantas vogais
existem na frase e qual a percentagem relativamente à totalidade dos
caracteres."""
resposta= True
while resposta:
continuar=True
while continuar:
str=input(f'frase com mais de 10 caracteres')
if len(str)>=10:
continuar=False
n=0
for i in range(0,len(str),1):
if str[i].lower()=='a'or str[i].lower()=='e' or str[i].lower()=='i' or
str[i].lower()=='o' or str[i].lower()=='u':
n+=1
desconto=0.30
precoKm=0.12
valor=0.0
resposta= True
while resposta:
continuar=True
while continuar:
distancia=int(input(f'distancia:'))
if distancia>0:
continuar=False
nNoites=-1
while nNoites<0:
nNoites=int(input(f'Noites:'))
valor=distancia*precoKm
if distancia>200 and nNoites >5:
valor=valor*(1-desconto)
x='q'
while x.lower() !='s' and x.lower()!='n':
x=input('continuar? s/n')
if x.lower() !='s':
resposta=False
resposta= True
while resposta:
n=-1
while n<100 or n>40000:
n=int(input(f'numero >=100 e <= 40000:'))
div=n
soma=0
while div>0:
resto=div%10
div=div//10
if not (resto%2==0):
soma+=resto
x='q'
while x.lower() !='s' and x.lower()!='n':
x=input('continuar? s/n')
if x.lower() !='s':
resposta=False