+ 3
[Solwed]How i make a calculator by python??
34 ответов
- 4
For +:
x = int(input())
y = int(input())
print(x + y)
For -:
x = int(input())
y = int(input())
print(x - y)
For /:
x = int(input())
y = int(input())
print(x/y)
For *:
x = int(input())
y = int(input())
print(x * y)
All in one:
x, action, y = input(), input(), input()
print(eval(f"{x} {action} {y}"))
+ 6
InfiniteCore Why have you directly given the answer without seeing his try?
+ 6
Sometimes it's better to see how
+ 4
If you don't mean a graphical calculator just an expression solver then you can simply do
print(eval(input("enter expression to calculate\n")))
sample input:50+50*2
output: 150
+ 1
A tip calculator then?
+ 1
yug vaishnav If you got the answer please add a [SOLVED] tag in the heading so that it's clear that the question is answered.
Thank you!
+ 1
Animesh Das okay, this code is good for begginers, but then at least make it smaller, don't repeat same commands (like num1=int(input(...))) many times
+ 1
Realy nice question! Calculator isn’t very easy.
Look at my Ruby code:
https://code.sololearn.com/c98jag713U9p/?ref=app
For - and : i tried to find bigest operand.
+ 1
Ashas Yiksvorogom sometimes yes just like on Ruby. But on Python we sould use if constructions or match operator. If is harder than match. :)
+ 1
while true:
x=int(input("number 1"))
y=int(input("number 2"))
z=int(input("what do"))
t=xzy
+ 1
"""This one is super simple. You can also use math values like pi and math functions like factorial()"""
from math import *
quit_keywords = ["Quit", "Q", "quit", "q"]
while True:
a = input(" Enter: ")
if a in quit_keywords:
print(" Quiting...")
break
else:
b = "c = {}".format(a)
exec(b)
print(" Result:", c, "\n")
0
Can you give more details about what you exactly want to do?
0
I want to find percentage of some numbers.
0
Take the numbers as input
Place them in variables
Do what you want with them ( sum / subtract & ... )
Take that as output
0
InfiniteCore Maybe 🤷
0
Good luck
0
You can declare the function calculator and place the operations you want to perform( addition,subtraction,etc..)
Declare variables
Give the input to perform the function
0
Use tkinter,math,cmath,numpy and scipy modules
0
HI
0
You could technically also use Stacks to implement bodmas if you don't want your calculator's potential to be limited to x number of inputs with one operator limit.