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
8 Respuestas
+ 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.
+ 7
You should convert da and db to int (or float) to make calculations with them
+ 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)
+ 3
convert the type to numerical type like int or float first before any operation.
int(da)/2;
+ 3
da,db = map(float, input().split())
+ 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));
+ 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♥️
0