I have a little math problem in python. Therefore, I have several variables, x , y and answer :
>>>x = 20 >>>y = 21 >>>answer = x / y * 100 >>>answer 0
This way it outputs null. OK I know that it prints zero, because I had to print x = 20.0 instead of printing x = 20 .
But I still need to print:
95.2380952381
How can i do this?
Note. Can't I just write x = 20.0 ?
And also I tried to do it like this:
x1 = str(x) + '.0' result = int(x1) / y * 100
But Python will tell me the error:
ValueError: invalid literal for int() with base 10: '20.0'
So how can I fix this?
source share