|
发表于 2021-3-13 11:50:34
|
显示全部楼层
def xiatiya(a,b):
if a >= b:
xiatiya(a//b,b)
print(a%b,end = '')
我们看xiatiya这个函数
if和print()在同一个缩进上
就是不论执不执行if中的内容,最终都会print()
xiatiya(131,2)
相当于执行
xiatiya(65,2)
print(131%2,end='')
相当于
xiatiya(32,2)
print(65%2,end='')
print(131%2,end='')
相当于
xiatiya(16,2)
print(32%2,end='')
print(65%2,end='')
print(131%2,end='')
相当于
xiatiya(8,2)
print(16%2,end='')
print(32%2,end='')
print(65%2,end='')
print(131%2,end='')
相当于
xiatiya(4,2)
print(8%2,end='')
print(16%2,end='')
print(32%2,end='')
print(65%2,end='')
print(131%2,end='')
相当于
xiatiya(2,2)
print(4%2,end='')
print(8%2,end='')
print(16%2,end='')
print(32%2,end='')
print(65%2,end='')
print(131%2,end='')
相当于
xiatiya(1,2)
print(2%2,end='')
print(4%2,end='')
print(8%2,end='')
print(16%2,end='')
print(32%2,end='')
print(65%2,end='')
print(131%2,end='')
相当于
print(1%2,end='')
print(2%2,end='')
print(4%2,end='')
print(8%2,end='')
print(16%2,end='')
print(32%2,end='')
print(65%2,end='')
print(131%2,end='')
结果 |
|