Scientific writing of a decimal number
def toFloat(arr):
number= ""
for chr in arr:
if chr!= '':
number+= chr
return float(number)
def transformation(number):
if number >=1 and number < 10:
return str(number) + ' * 10^0'
num = str(float(number))
isNegative = True
if float(number) >= 1 :
num = num[::-1]
isNegative = False
num = list(num)
power = 0
for index in range(0 , len(num)):
if index == 0 or num[index] == '.' :
num[index] = ''
continue
if int(num[index]) > 0:
power+=1
num.insert(index+1 , '.')
if float(number) >= 1 :
num = num[::-1]
break
power+=1
num[index] = ''
if isNegative:
return str(toFloat(num))+ ' * 10^-' + str(power)
return str(toFloat(num))+ ' * 10^' + str(power)
if _name_ == '_main_':
number = float(input("Enter a number:"))
print("Scientific writing number is :",transformation(number))