怎么做套版网站,互联网创业项目的效果,淄博建设公司网站,广州公司注册一网通【算法分析】 本算法需要用到的Python知识点#xff1a; 1.求余%#xff0c;整除 //。例如#xff0c;7%21#xff0c;7//23#xff0c;而7/23.5。 2.Python列表的 append 及 pop 函数。 • append(x) 函数用于将 x 添加到现有列表中。 • pop() 函数默认移除列表中…【算法分析】 本算法需要用到的Python知识点 1.求余%整除 //。例如7%217//23而7/23.5。 2.Python列表的 append 及 pop 函数。 • append(x) 函数用于将 x 添加到现有列表中。 • pop() 函数默认移除列表中的最后一个元素并且返回该元素的值。 3.Python字符串通过运算符 实现连接操作。如xayb则xyab。 4.Python可以通过 str(x) 函数,将 x 强制转换成字符串。【算法代码】
# 用函数实现十进制与二进制的转换
def oct2bin(n):ls[]answhile n!0:tn%2ls.append(t)nn//2while len(ls)!0:ansansstr(ls.pop())print(ans)xeval(input(Please input an integer:))
oct2bin(x)