-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
49 lines (41 loc) · 1.45 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def calc(n):
parts = n.replace('*','x').split('x10^')
number = parts[0]
# Scientific Notation Fixer
if len(parts) == 2:
exponent = int(parts[1])
# Decimal
if number[0] == '0':
zeroCount = 0
for i in number:
if i == '0': zeroCount -= 1
if i != '0': break
found = number.lstrip('0')
if int(found) > 10: found = f'{found[:1]}.{found[1:]}'
print(f'{found}x10^{zeroCount + exponent}')
# Integer
else:
found = number.rstrip('0')
if int(found) > 10:
found = f'{number[:1]}.{number[1:]}'
print(f'{found.rstrip("0")}x10^{len(found.split(".")[1]) + exponent}')
else:
print('hi')
elif len(parts) == 1:
# Decimal
if number[0] == '0':
zeroCount = 0
value = number.lstrip('0')
if int(value) > 10:
value = f'{value[:1]}.{value[1:]}'
for i in number:
if i == '0': zeroCount -= 1
if i != '0': break
print(f'{value}x10^{zeroCount}')
# Integer
else:
if int(number) > 10:
number = number[:1] + '.' + number[1:]
temp = number.rstrip('0')
print(f'{temp}x10^{len(number.split(".")[1])}')
calc('720000')