- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex82.py
More file actions
Latest commit
28 lines (24 loc) · 666 Bytes
/
Copy pathex82.py
File metadata and controls
28 lines (24 loc) · 666 Bytes
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
'''
八进制转换为十进制
'''
defoct2dec(num_string, flag=1):
s=0
ifflag==1:
foriinrange(len(num_string)):
s+=float(num_string[-i-1])*8**i
elifflag==-1:
foriinrange(len(num_string)):
s+=float(num_string[i])*8**(-i-1)
returns
octal_num=input("输入一个八进制数:")
s=0
minus=-1
ifoctal_num[0] =="-":
octal_num=octal_num.replace("-", "")
minus=1
if"."inoctal_num:
str_list=octal_num.split(".")
result=oct2dec(str_list[0]) +oct2dec(str_list[1], flag=-1)
else:
result=oct2dec(octal_num)
print(-minus*result)