Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!