- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
x = str(x) # x == '987.654'
dot = x.find('.') # dot == 3
whole = x[:dot] # whole == '987'
nums = '0123456789' #
tenths = x[(dot + 1):(dot + 2)] # tenths == '6'
max_digits = 6 # Directions say x is not > 100,000
filler = max_digits - dot # filler == 3 (dot is equal to the number of digits in whole)
big_num = ('0' * filler) + whole # big_num == '000987'
e5 = (nums.find(big_num[0:1])) * 100000 # e5 == 0
e4 = (nums.find(big_num[1:2])) * 10000 # e4 == 0
e3 = (nums.find(big_num[2:3])) * 1000 # e3 == 0
e2 = (nums.find(big_num[3:4])) * 100 # e2 == 900
e1 = (nums.find(big_num[4:5])) * 10 # e1 == 80
e0 = (nums.find(big_num[5:6])) # e0 == 7
the_decider = '9'.find(tenths) + '8'.find(tenths) + '7'.find(tenths) + '6'.find(tenths) + '5'.find(tenths) + 5
rounded = (e5 + e4 + e3 + e2 + e1 + e0) + the_decider
print rounded
Эта, кхм, программа предназначается для округления положительных натуральных чисел величиной до 100000.