Reputation: 4093
I am writing a program to to check if the quotient yielded by the division is a whole number or not.
The dividend (numerator if division) is the given input integer. The divisor (Denominator) is the reverse of the dividend.
I implemented reversion for 90
, for example,by the following code:
>>> str(90)[::-1]
It yielded the following result:
>>> str(90)[::-1]
09
Now if i perform division between 90 (input) and 09 (reverse), it yields an error:
>>> 90/09
SyntaxError: invalid token
What should be done to eradicate this error and get the correct answer 10.0
?
How to ignore that zero if it is in the starting of either divisor or dividend?
Upvotes: 0
Views: 536
Reputation: 6784
One thing is that you are trying to interactively calculate this and you are literally typing 09
in the interpreter. Numbers starting with 0 are interpreted as octal numbers (cf. What do numbers starting with 0 mean in python?) and 09 is an invalid octal representation.
The other thing is that the division will not work at all if you do not convert your string back to int or float, so it should be something like this:
num = 90
res = 90 / float(str(90)[::-1])
print(res)
Upvotes: 1