|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
有三问,麻烦了~
(一)def power(x, y):
result = 1
for i in range(y):
result *= x
return result
print(power(2, 3))
第三和四句看不懂
(二)def gcd(x, y):
while y:
t = x % y
x = y
y = t
return x
print(gcd(4, 6))
其中x=4,y=6,不应该先比较x,y的大小嘛
(三)def Dec2Bin(dec):
temp = []
result = ''
while dec:
quo = dec % 2
dec = dec // 2
temp.append(quo)
while temp:
result += str(temp.pop())
return result
print(Dec2Bin(62))
里面while temp看不懂
1,就是x乘上三次(x * x * x)
y等于几就是几个x相乘。
2,同上,就是为了保存每次x相乘的结果。
比如x = 5,那么第一次,result = 1 * 5 = 5
第二次,result = 5 * 5 = 25
第三次,result = 25 * 5 = 125
所以5的三次方就是125
|
|