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 . ?

18th Jan 2022, 4:20 PM
Karim Karim
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`)
18th Jan 2022, 5:03 PM
NEZ
NEZ - avatar
+ 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))
19th Jan 2022, 10:55 PM
Azamat Shermatov
Azamat Shermatov - avatar
21st Jan 2022, 2:31 AM
NEZ
NEZ - avatar
+ 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
21st Jan 2022, 2:43 AM
Bob_Li
Bob_Li - avatar
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?
18th Jan 2022, 4:43 PM
Emerson Prado
Emerson Prado - avatar
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?
18th Jan 2022, 4:46 PM
Karim Karim
0
Yes, I know. But I don't know what is the question. What's the difficulty on inputting the operator?
18th Jan 2022, 4:53 PM
Emerson Prado
Emerson Prado - avatar
0
How we create a simple calculator 😂😂 ?
18th Jan 2022, 4:54 PM
Karim Karim
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.
18th Jan 2022, 4:58 PM
Emerson Prado
Emerson Prado - avatar
0
Emerson Prado ㅀㅀㅀ thanks .âœŒïžđŸ™‚
18th Jan 2022, 5:12 PM
Karim Karim
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.
20th Jan 2022, 6:53 AM
Bob_Li
Bob_Li - avatar
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
20th Jan 2022, 7:11 AM
Bob_Li
Bob_Li - avatar