You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

11 months ago
# -*- coding: utf-8 -*-
# Time : 2023/10/30 15:49
# Author : lirunsheng
# User : l'r's
# Software: PyCharm
# File : X2.py
# encoding: utf-8
# 第一题讲二进制数转换为10进制数
def binToDec_int(b):
d = 0
for i in range(len(b)):
# 请在此添加代码补全函数BinToDec_int()
# -----------Begin----------
if b[i] == '1':
d = d + 2 ** (len(b) - 1 - i)
# ------------End-----------
return d
def binToDec_float(b):
# 请在此添加代码补全函数BinToDec_int()
# -----------Begin----------
d = 0.0
for i in range(len(b)):
# 请在此添加代码补全函数BinToDec_int()
# -----------Begin----------
if b[i] == '1':
d = d + 2 ** (-(i+1))
# ------------End-----------
return d
if __name__ == '__main__':
tests = []
inputlist = input()
# print(type(inputlist))
# for i in inputlist:
# tests.append(str(i))
tests = inputlist.split(',')
for num in tests:
if '.' in num:
num1 = num.split('.')
print(binToDec_int(num1[0])+binToDec_float(num1[1]))
else:
print(binToDec_int(num))