Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
how to make a percentage calculator using python

I want to develop a calculator that does simple math using Python with user input for one of my projects for high school, but I can't figure out how to write the input for percentage. So I was hoping that someone could assist me.

Here is my code---

import math

print("What kind of operation do you want to perform? ")
print("a. Add")
print("b. Subtract")
print("c. Multiply")
print("d. Divide")  
print("e. Square Root")
print("f. Percentage")
print("Please select by choosing a, b, c, d, e, or f.")

def add(ip1, ip2):
  return ip1 + ip2

def subtract(ip1, ip2):
  return ip1 - ip2

def multiply(ip1, ip2):
  return ip1 * ip2

def divide(ip1, ip2):
  return ip1 / ip2

def squareroot(ip1):
  return math.sqrt(ip1)

def percentage(ip1)
  return    

def main():
  option = (input("Choose the sort of calculation you want to perform: "))

  ip1 = int(input("Start by entering the first number you'd want to calculate: "))
  ip2 = int(input("Fill in the second number you want to calculate: "))

 
  if option == "a":
    print(ip1, "+", ip2, "=", add(ip1, ip2))

  elif option == "b":
    print(ip1, "-", ip2, "=", subtract(ip1, ip2))
  elif option == "c":

    print(ip1, "*", ip2, "=", multiply(ip1, ip2))

  elif option == "d":
    print(ip1, "/", ip2, "=", divide(ip1, ip2))

  elif option == "e":
    print(squareroot(ip1))

  else:
    print("Wrong Input")


main()
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What I understand from your question is that you want to calculate what percentage of the 2nd input is the 1st input. If that is the case, then you could do something like :-

def percentage(ip1, ip2):
  return ip1 / ip2 * 100

What this basically does, is that it divides the first input by the second input and multiplies the outcome by hundred. This will output what percentage the first input is of the second input.

Eg:-

inp1 = 5, inp2 = 10

process: 5 / 10 * 100

output: 50(%)

P.S. - You also need to add the elif clause for option == f.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda