How transform string "*" in operation * between two nums in Python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How transform string "*" in operation * between two nums in Python?

Hello world! Someone help me please I dont understand: I try to write simple specific callculator, need to input 2 nums and 1 opperation: +, /, *, -. When we input + in interpretator its a string, I need paste that value betwen nums and have summ in the end. How I can do it?/ всем привет, подскажите пож-та, не могу решить вопрос по переводу знака умножения стринг, в знак умножения который позволит мне умножить два числа. Если кто нибудь напишет примерный код буду благодарен. A = int (input ("enter num1: ")) B = int (input ("enter num2: ")) C = input ("enter operation: ") If c =="*": # основной вопрос, интерпретатор не #понимает что я хочу от него Print (a * b ) # можно ли как то не писать сам знак #умножения а вставить значение из того что я #ввел? Else: Print ("sorry bro")

23rd Feb 2019, 3:33 AM
Rebelio Rebelionovich
Rebelio Rebelionovich - avatar
6 Answers
+ 2
What kind of error is it showing? And try to share the link of your code.
23rd Feb 2019, 3:43 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 1
Hi! Its not realy what I need in this calc. I wont input 2 nums, input operation. Thats a task
23rd Feb 2019, 3:39 AM
Rebelio Rebelionovich
Rebelio Rebelionovich - avatar
0
Have you tried eval() function? It'll make it easier. >>>str= "2*3" >>>eval(str) >>>6
23rd Feb 2019, 3:36 AM
Шащи Ранжан
Шащи Ранжан - avatar
0
I think your above code should work. What's the problem?
23rd Feb 2019, 3:40 AM
Шащи Ранжан
Шащи Ранжан - avatar
0
Its not working! When I input * or + my code take erorr
23rd Feb 2019, 3:43 AM
Rebelio Rebelionovich
Rebelio Rebelionovich - avatar
0
C = str(input ("enter operation: "))
26th Feb 2019, 6:13 PM
Kashif Nawaz
Kashif Nawaz - avatar