Python3 的函数

1、编写power(x,y)函数返回x的y次幂值

def power(x,y):
    return x**y

2、求最大公约数

def gcd(x,y):
    r=x%y
    x=y
    y=r
    if r==0:
        print(x)
    else:
        gcd(x,y)

3、十进制到二进制转换

def dbin(x):
    list1 = []
    bi=''
    while x != 0:
        if x%2==1:
            #bi+="1"
            list1.append(1)
        elif x%2==0:
            #bi+='0'
            list1.append(0)
        x=x//2
    while list1:
        bi+=str(list1.pop())
    return bi
原文地址:https://www.cnblogs.com/PythonFCG/p/8353372.html