Python Exercise (Question) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Python Exercise (Question)

Hey guys, so I got this question: a nonnegative integer is given. Find the number of tens in its decimal record (that is, the second digit on the right of its decimal record). Does anyone knows how to solve it because I am stuck and I've no idea how to do this!

11th Oct 2017, 8:18 PM
Daniel
Daniel - avatar
2 Answers
+ 3
Maybe I didn't quite get you, but why can't you just divide this integer by 10 and round it?
11th Oct 2017, 8:24 PM
TheSage
TheSage - avatar
+ 4
print(len(string(Number).split('.')[1])) if number is 45.675611 it will return 6 here number is converted to string, then it's split in two parts along the decimal, and then it tells the length of the second part. maybe it's looking bad but that's what you can do since, the decimal point in binary represents infinite many digits as there are infinite zeroes at the right equivalent to the number. physically they are different due to precision but numerically they are same the in-built function function by Python also works after making it a string,the same way actually, you will have to make it string and then call the method. print(decimal.Decimal(String(Number)).as_tuple().exponent)
12th Oct 2017, 1:53 AM
Sandeep Chatterjee