Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

102
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda