在这段视频中(7分30秒),我从这段视频中复制的下面的代码返回3,虽然 地雷返回4.04秒。 我不明白为什么视频中的代码返回Int,尽管我的代码返回Float
https://www.youtube.com/watch?v=HWW-jA6YjHk&list=UUNc-Wa_ZNBAGzFkYbAHw9eg&index=29
def num_coins(cents):
if cents < 1:
return 0
coins = [25, 10, 5, 1]
num_of_coins = 0
for coin in coins:
num_of_coins += cents / coin
cents = cents % coin
if cents == 0:
break
return num_of_coins
print(num_coins(31))
使用此选项可获得正确答案:
/
运算符对于Python2和Python3不相似相关问题 更多 >
编程相关推荐