作业5:小数转换成科学计数法,主要分两种情况讨论(对整数不成立的哦)
a = input()
list1 = list(a)
if list1[0] != '0':
count = 0
for i in range(len(list1)):
if list1[i] != '.':
count += 1
else:
break
list1.remove('.')
print(list1[0] + '.', end='')
for j in range(1, len(list1)):
print(list1[j], end='')
print('e', end='')
print(count - 1)
if list1[0] == '0':
count = 0
index = 0
list2 = list1[2:]
for i in range(len(list2)):
if list2[i] == '0':
count = count + 1
else:
break
for j in range(len(list1)):
if list1[j] == '0' or list1[j] == '.':
index += 1
else:
break
list3 = list1[index:]
print(list3[0], end='')
if len(list3) != 1:
print('.', end='')
for k in range(1, len(list3)):
print(list3[k], end='')
print('e-', end='')
print(count+1)
0.0023
2.3e-3
3.256
3.256e0
|