# -*- coding: utf-8 -*-
import math
def return_answer(num):
sys_num_1 = 2 # из двоичной системы
main_answer = 0
negative = ""
if num.startswith("-"):
num = num[1:]
negative = "-"
num_for_arr = 1
for i in num:
if i != '0':
answ = int(i) * sys_num_1 ** int(len(num)-num_for_arr)
main_answer += answ
num_for_arr += 1
return "%s%s" % (negative, main_answer)
def main():
while True:
num = input("\nВведите число: ")
print("\nответ:", return_answer(num))
if __name__ == '__main__':
main()
# -*- coding: utf-8 -*-
import math
def return_answer(num):
sys_num_1 = 2 # из двоичной системы
main_answer = 0
negative = ""
if num.startswith("-"):
num = num[1:]
negative = "-"
num_for_arr = 1
for i in num:
if i != '0':
answ = int(i) * sys_num_1 ** int(len(num)-num_for_arr)
main_answer += answ
num_for_arr += 1
return "%s%s" % (negative, main_answer)
def main():
while True:
num = input("\nВведите число: ")
print("\nответ:", return_answer(num))
if __name__ == '__main__':
main()