0
If some one can answer me
In python String----> str and it for words etc Integer -----> int . And it for numbers Float ------> id True or False But what about + - * / How can we identify it in a console . Let's say a simple calculator. And we put num 1 and num 2 .what about operation How can we put it . ?
13 Respostas
+ 1
Karim Karim
x=int(input("enter first no.: "))
y=input('enter the arithematic operation (+,-,*,/): ')
z=int(input('enter second no.: '))
if y=='-':
print(x-z)
elif y=='+':
print(x+z)
elif y=='*':
print(x*z)
elif y=='/':
print(x/z)
#you meant to make this?
If yes, then don't use the user prompt if you are using it in sololearn (cuz its of no use), if you are going to paste it in pydroid then it's just right.
(If you want to add any other operations, you can add more elifsđ)
edit]: you can take input as floats if you want (just change `int to float`)
+ 1
x = input("Enter the first number, operation and the second number(Example: 2+5 or 2-5 or 2*5 or 2/5): -> ")
print(x, "=", eval(x))
+ 1
Bob_Li, nice here are some other short codes too:
https://code.sololearn.com/cKFn0kY2d3Xj/?ref=app
https://code.sololearn.com/ck9rtCKNCAdK/?ref=app
+ 1
eval is evil...đ
But for simple practice, probably ok. Just don't use it for vulnerable situations.
https://stackoverflow.com/questions/1832940/why-is-using-eval-a-bad-practice
0
The question is quite confusing.
First, float is for numbers - True and False are booleans.
Next, which console do you mean?
Finally, what do you want to know about arithmetic operators?
0
Let's say .
X = float ( input ())
Y = float (input())
Z = X + Y
Print (Z)
What if we want from the user to put the operator to calculate Z .
Do u know what i mean?
0
Yes, I know. But I don't know what is the question. What's the difficulty on inputting the operator?
0
How we create a simple calculator đđ ?
0
There are a million ways. A simple one is just inputting two numbers and an operator, then doing the requested calculation and printing the result.
Go on code playground, start a code, link it inside the question with + buttom, and explain the difficulty.
0
Emerson Prado ă
€ă
€ă
€ thanks .âïžđ
0
+,-,*,/ are string characters when typed into input, so you can use switch to perform the proper operations.
eval should be avoided.
is there any reason why you would need three inputs if you could do it in one? unless you are using buttons, it is more user friendly to input the whole operation in one go.
Programming should be about giving people an easier way of doing something. Not the other way around.
0
'~NEZ' your name does not print out. Cool trick.đ
ok, I was looking at the proposed solutions and saw too many inputs for a simple problem.
ok, how about this?
shorter, no function, no if-else, no switch, no eval, can handle decimal values and spacing-tolerant(3+5 or 3 + 5 are ok)
https://code.sololearn.com/cWIk8IGdDrnD/?ref=app