Pls help to solve my problem

Question:
how to make calulator
Repl link:

type or paste code here
a=int(input("enter first number:"))
b=int(input("entaer secon number:"))
c=a+b
f=a*b
g=a-b
n=a/b
l=a%b
print("your addition of ", a,"and",b,"is", c)
print("your multiplication of ", a,"and", b,"is", f)
print("your subtraction of ", a,"and", b,"is", g)
print("your divison of ", a,"and", b,"is",n)
print("your percentage of ", a,"and", b,"is", l)
```py
code snippet

Hey @AKSHITDOTIYAL! Welcome to the community!

The % symbol does not calculate the percentage of the number; it is a modulus symbol, which means that it will return the remainder of the division.

So for example, we have 5 % 3. This will return 2 since when 5 is divided by 3, it will have a remainder of 2.

If you want to calculate the percentage of a value, consider using this:

l = a * (b / 100)

Hope this helps!

3 Likes

Welcome to the forums @AKSHITDOTIYAL!

As @savardo said, % is the modulus operator, it doesn’t calculate percentages.

Another thing you should note is that it is bad to name variables single letters. I’d rename them all to:

firstNumber = int(input("enter first number:"))
secondNumber = int(input("enter second number:"))
addedNumbers = firstNumber + secondNumber
multipliedNumbers = firstNumber * secondNumber
subtracedNumbers = firstNumber - secondNumber
dividedNumbers = firstNumber /  secondNumber
percentage = firstNumber / (secondNumber * 100)

print(firstNumber, "plus", secondNumber, "is", addedNumbers)
print(firstNumber, "multiplied by", secondNumber, "is", multipliedNumbers)
print(firstNumber, "minus", secondNumber, "is", subtractedNumbers)
print(firstNumber, "divided by", secondNumber, "is", dividedNumbers)
print(firstNumber, "percent of", secondNumber, "is", percentage)
2 Likes