0

Why can't I divide in Python?

I am not able to divide the input by 2 in Python. Pls. Solve the error... https://code.sololearn.com/cQU3JNALzTRS/?ref=app

21st May 2019, 2:16 PM
Manan
Manan - avatar
8 Answers
+ 4
An input from the user is a string by default. In order to perform mathematical operations on an input, you need to either change it to an integer or a float using int() or float() respectively.
21st May 2019, 2:21 PM
Russ
Russ - avatar
+ 7
You should convert da and db to int (or float) to make calculations with them
21st May 2019, 2:23 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 6
It’s just one line in code that you have to change: #da,db = input().split() da, db = map(int, input('Enter 2 Values sep. by space: \n').split()) num = da/2 num_final = num + db print(num_final)
21st May 2019, 2:44 PM
Lothar
Lothar - avatar
+ 3
convert the type to numerical type like int or float first before any operation. int(da)/2;
21st May 2019, 2:19 PM
Taste
Taste - avatar
+ 3
da,db = map(float, input().split())
21st May 2019, 2:42 PM
Russ
Russ - avatar
+ 2
https://docs.python.org/3/library/functions.html#input as far as know python, which is not so much. i dont think its possible to directly change its behavior. maybe you can write a function like this def input_int(text): return int(input(text));
21st May 2019, 2:42 PM
Taste
Taste - avatar
+ 2
Thanks Taste Russ Lothar Mert Yazıcı Thanks a lot for your help!!! The Sololearn community is the best community because of helpful members like you♄
21st May 2019, 2:49 PM
Manan
Manan - avatar
0
Mert Yazıcı Russ Taste Is there any way I could do get the input default as an float or int?đŸ€”
21st May 2019, 2:36 PM
Manan
Manan - avatar