Python小代码_12_生成前 n 行杨辉三角
def demo(t):
print([1])
print([1, 1])
line = [1, 1]
for i in range(2, t):
r = []
for j in range(0, len(line) - 1):
r.append(line[j] + line[j + 1])
line = [1] + r + [1]
print(line) demo(10) #输出结果
'''
[1]
[1, 1]
[1, 2, 1]
[1, 3, 3, 1]
[1, 4, 6, 4, 1]
[1, 5, 10, 10, 5, 1]
[1, 6, 15, 20, 15, 6, 1]
[1, 7, 21, 35, 35, 21, 7, 1]
[1, 8, 28, 56, 70, 56, 28, 8, 1]
[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]
'''
Python小代码_12_生成前 n 行杨辉三角的更多相关文章
- Python小代码_13_生成两个参数的最小公倍数和最大公因数
def demo(m, n): if m > n: m, n = n, m p = m * n while m != 0: r = n % m n = m m = r return (int(p ...
- Python小代码_11_生成小于 n 的裴波那契数列
def fib(n): a, b = 1, 1 while a < n: print(a, end=' ') a, b = b, a + b fib(100000) #输出结果 #1 1 2 3 ...
- 求第n行杨辉三角(n很大,取模
1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 typedef long long l ...
- python小工具myqr生成动态二维码
python小工具myqr生成动态二维码 (一)安装 (二)使用 (一)安装 命令: pip install myqr 安装完成后,就可以在命令行中输入 myqr 查看下使用帮助: myqr --he ...
- Python小代码_2_格式化输出
Python小代码_2_格式化输出 name = input("name:") age = input("age:") job = input("jo ...
- Python小代码_1_九九乘法表
Python小代码_1_九九乘法表 max_num = 9 row = 1 while row <= max_num: col = 1 while col <= row: print(st ...
- 【Python初级】由生成杨辉三角代码所思考的一些问题
杨辉三角定义如下: 1 / \ 1 1 / \ / \ 1 2 1 / \ / \ / \ 1 3 3 1 / \ / \ / \ / \ 1 4 6 4 1 / \ / \ / \ / \ / \ ...
- 给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。
该题还是考杨辉三角计算,只不过最后每一行都放入List集合中,然后返回,直接看代码: public static List<List<Integer>> generate(in ...
- 1233: 输出杨辉三角前n行(Java)
WUSTOJ 1233: 输出杨辉三角前n行 题目 原题链接 Description 输出杨辉三角前n行. Input 输入一个数n(n <= 9) Output 输出杨辉三角前n行.(注意行末 ...
随机推荐
- 集智robot微信公众号开发笔记
开发流程 公众号基本配置(首先得有公众平台账号) 在开发菜单的基本配置中填写好基本配置项 首先配置服务器地址.Token.和消息加密密钥(地址为开发者为微信验证留的接口.token可以随便填写,只要在 ...
- ccf认证 201709-4 通信网络 java实现
试题编号: 201709-4 试题名称: 通信网络 时间限制: 1.0s 内 ...
- HashMap就是这么简单【源码剖析】
前言 声明,本文用得是jdk1.8 前面已经讲了Collection的总览和剖析List集合以及散列表.Map集合.红黑树的基础了: Collection总览 List集合就这么简单[源码剖析] Ma ...
- Spring(三):Spring整合Hibernate
背景: 本文主要介绍使用spring-framework-4.3.8.RELEASE与hibernate-release-5.2.9.Final项目整合搭建的过程. 开发环境简介: 1).jdk 1. ...
- amd屏幕亮度无法调整,无法调节亮度
1:CMD+R键打开"运行",输入"regedit"进入注册表 2:搜索"KMD_EnableBrightnessInterface2",找 ...
- PHP面向对象-看父类调用子类方法
大部分面向对象编程语言中,父类是不允许调用子类的方法的,但是PHP中可以 1.父类调用子类方法示例 class A { public function testa() { $this->test ...
- [LeetCode] My Calendar I 我的日历之一
Implement a MyCalendar class to store your events. A new event can be added if adding the event will ...
- [LeetCode] Palindromic Substrings 回文子字符串
Given a string, your task is to count how many palindromic substrings in this string. The substrings ...
- 【Swift】图文混排,ios开发中在textfield或textView中插入图片
在ios开发中,我们一般都是在textfield或者textView中输入文字.当我们需要插入图片的时候其实也是很简单的 我们需要利用的textfield,textView的属性化文本,将图片以附件的 ...
- animation-timing-function的steps详解
W3C里的定义: animation-timing-function 规定动画的速度曲线. 这个属性有很多取值, linear: 线性过渡.等同于贝塞尔曲线(0.0, 0.0, 1.0, 1.0) e ...