+ 3

[Solwed]How i make a calculator by python??

1st Apr 2022, 6:23 AM
yug vaishnav
34 Answers
- 3
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}"))
1st Apr 2022, 7:46 AM
Danila 🧊
Danila 🧊 - avatar
+ 7
Sometimes it's better to see how
1st Apr 2022, 8:38 AM
Danila 🧊
Danila 🧊 - avatar
+ 6
InfiniteCore Why have you directly given the answer without seeing his try?
1st Apr 2022, 8:36 AM
Adil
Adil - avatar
+ 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
1st Apr 2022, 11:44 PM
Ireneo language
+ 1
A tip calculator then?
1st Apr 2022, 6:31 AM
Orisa
Orisa - avatar
+ 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!
2nd Apr 2022, 6:12 AM
Adil
Adil - avatar
+ 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
2nd Apr 2022, 1:34 PM
Ashas Yiksvorogom
Ashas Yiksvorogom - avatar
+ 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.
2nd Apr 2022, 1:43 PM
aewerdev
aewerdev - avatar
+ 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. :)
2nd Apr 2022, 3:13 PM
aewerdev
aewerdev - avatar
+ 1
while true: x=int(input("number 1")) y=int(input("number 2")) z=int(input("what do")) t=xzy
3rd Apr 2022, 2:45 AM
Çılgın Pilot
+ 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")
5th Apr 2022, 7:37 AM
Khun Set
Khun Set - avatar
0
Can you give more details about what you exactly want to do?
1st Apr 2022, 6:26 AM
Orisa
Orisa - avatar
0
I want to find percentage of some numbers.
1st Apr 2022, 6:27 AM
yug vaishnav
0
Take the numbers as input Place them in variables Do what you want with them ( sum / subtract & ... ) Take that as output
1st Apr 2022, 7:43 AM
Ardavan Eskandari
Ardavan Eskandari - avatar
0
InfiniteCore Maybe 🤷
1st Apr 2022, 8:39 AM
Adil
Adil - avatar
0
Good luck
1st Apr 2022, 9:45 AM
Abdul Rahman
Abdul Rahman - avatar
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
1st Apr 2022, 5:23 PM
Penumudi Lavanya
Penumudi Lavanya - avatar
0
Use tkinter,math,cmath,numpy and scipy modules
1st Apr 2022, 11:21 PM
Kelvin Mubanga
Kelvin Mubanga - avatar
0
HI
2nd Apr 2022, 8:14 AM
Kailash126 Runkana126
Kailash126 Runkana126 - avatar
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.
2nd Apr 2022, 11:06 AM
Aryan Roy
Aryan Roy - avatar