我姐发来一道奥数题
想起了前两天学过的递归,于是,有了自己独立编制的第一个小程序
def math(n): if n == 1: return 1 else: return (n-1)*4 + math(n-1) n = int(input('请输入要摆放的层数:')) print('这一层有%d个正方体'%math(n)) total = 0 for i in range(1,n+1): total += math(i) print('一共有%d个正方体'%total)
纪念下,加油!
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
QQ咨询|关于我们|Archiver|手机版|小黑屋|( 辽ICP备15012455号-4 ) Powered by 期权论坛 X3.2 © 2001-2016 期权工具网&期权论坛 Inc.
下载期权论坛手机APP