Skip to content

Instantly share code, notes, and snippets.

@johnnyferreiradev
Created January 31, 2024 20:12
Show Gist options
  • Save johnnyferreiradev/8a40f6c742a15d3aaab4c60292f87c0b to your computer and use it in GitHub Desktop.
Save johnnyferreiradev/8a40f6c742a15d3aaab4c60292f87c0b to your computer and use it in GitHub Desktop.
Exercice FACCAT - Questions soluctions
# question 5
def getPredecessor():
try:
value = int(input("Digite um número inteiro: "))
return value - 1
except:
print("Tipo inválido. Você deve inserir um número inteiro.")
# question 6
def getRectangularArea():
try:
width = abs(float(input("Digite o valor da largura do retângulo: ")))
height = abs(float(input("Digite o valor da altura do retângulo: ")))
return width * height
except:
print("Os valores de altura ou largura são inválidos.")
# question 7
def getAgeInDays():
try:
print("Digite sua idade:")
years = abs(int(input("Anos: ")))
months = abs(int(input("Mêses: ")))
days = abs(int(input("Dias: ")))
totalDaysByMonth = 30
totalDaysByYear = 365
return f"Sua idade em dias: {days + (months * totalDaysByMonth) + (years * totalDaysByYear)}"
except:
print("Os valores informados são inválidos.")
# question 8
def getPercentageOfVotes():
try:
totalVoters = abs(int(input("Digite o total de eleitores: ")))
totalValidVotes = abs(int(input("Quantidade de votos válidos: ")))
totalBlankVotes = abs(int(input("Quantidade de votos brancos: ")))
totalNullVotes = abs(int(input("Quantidade de votos nulos: ")))
votesCount = totalValidVotes + totalBlankVotes + totalNullVotes
if totalVoters < votesCount:
return "Erro. Total de votos não pode ser maior que o número de eleitores."
if totalVoters != votesCount:
totalNullVotes = totalNullVotes + totalVoters - votesCount
validPercentage = totalValidVotes * 100 / totalVoters
blankPercentage = totalBlankVotes * 100 / totalVoters
nullPercentage = totalNullVotes * 100 / totalVoters
return f"Válidos {validPercentage}%; Brancos: {blankPercentage}%; Nulos: {nullPercentage}%."
except:
print("Os valores informados são inválidos.")
# question 9
def calculateSalaryAdjustment():
try:
salaryValue = abs(float(input("Valor do salario (R$): ")))
adjustmentPercentage = float(input("Porcentagem do reajuste: "))
salaryWithAdjustment = salaryValue + (salaryValue * adjustmentPercentage / 100)
return f"Novo salário após reajuste: {salaryWithAdjustment if salaryWithAdjustment >= 0 else 0}"
except:
print("Os valores informados são inválidos.")
# question 10
def calculateFinalValueOfTheNewCar():
try:
fabricValue = abs(float(input("Insira o valor de fábrica (R$): ")))
distributorPercentage = 0.28
taxes = 0.45
newCarValue = (
fabricValue + (fabricValue * distributorPercentage) + (fabricValue * taxes)
)
return f"Valor final do carro: {newCarValue}"
except:
print("Os valores informados são inválidos.")
# question 11
def calculateFinalValueOfTheNewCar():
try:
totalSalesCars = abs(int(input("Total de carros vendidos: ")))
totalSalesValue = abs(float(input("Valor total em vendas (R$): ")))
salary = abs(float(input("Salário fixo (R$): ")))
extraValuePerCar = abs(float(input("Valor extra por carro vendido (R$): ")))
newSalary = (
salary + (totalSalesCars * extraValuePerCar) + (totalSalesValue * 0.05)
)
return f"Novo salário: {newSalary}"
except:
print("Os valores informados são inválidos.")
# question 12
def fahrebheitToCeulsis():
try:
temperatureInFahrebheit = float(input("Digite a temperatura em Fahrebheit: "))
temperatureInCelcius = ((temperatureInFahrebheit - 32) * 5) / 9
return f"Temperatua em Celcius: {temperatureInCelcius}"
except:
print("Os valores informados são inválidos.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment