当前位置:网站首页>Basic exercise of test questions Yanghui triangle (two-dimensional array and shallow copy)
Basic exercise of test questions Yanghui triangle (two-dimensional array and shallow copy)
2022-06-13 02:07:00 【Jerry-hao】
The upper and left boundaries are added here , Easy to calculate
n = int(input())
b=[ [0]*(n+1) for i in range(n+1)]
b[1][1]=1
#print(" Before operation :",b)
for i in range(1,n):
i=i+1
for j in range(i):
j=j+1
b[i][j]=b[i-1][j-1] + b[i-1][j]
#print(' The first ',i,' That's ok ',b)
for i in range(n):
i = i+1
for j in range(i):
j=j+1
print(b[i][j],end=' ')
print()
The creation of two-dimensional array , Careful shallow copy :
How to create a two-dimensional array as well as python in [0 ]* n And [0 for _ in range(n)] The difference and connection _ Jiansheng Tudou's blog -CSDN Blog
To simplify the : Output directly after the operation
n = int(input())
b=[ [0]*(n+1) for i in range(n+1)]
b[1][1]=1
#print(" Before operation :",b)
print(b[1][1])
for i in range(1,n):
i=i+1
for j in range(i):
j=j+1
b[i][j]=b[i-1][j-1] + b[i-1][j]
print(b[i][j],end=' ')
print()
边栏推荐
- dfs与bfs解决宝岛探险
- 一、搭建django自动化平台(实现一键执行sql)
- Share three stories about CMDB
- [learning notes] xr872 audio driver framework analysis
- 华为设备配置双反射器优化虚拟专用网骨干层
- Ruixing coffee moves towards "national consumption"
- (no plug-in) summary of vim basic shortcut keys
- pringboot之restfull接口规范注解(二)
- Combining strings and numbers using ssstream
- [the fourth day of actual combat of stm32f401ret6 smart lock project in 10 days] voice control is realized by externally interrupted keys
猜你喜欢
C language conditional compilation routine
华为设备配置私网IP路由FRR
Gome's ambition of "folding up" app
When AI meets music, iFLYTEK music leads the industry reform with technology
Magics 23.0 how to activate and use the slice preview function of the view tool page
The new wild prospect of JD instant retailing from the perspective of "hour shopping"
Why is Huawei matebook x Pro 2022 leading a "laptop" revolution
华为设备配置虚拟专用网FRR
Devaxpress Chinese description --tdximageslider (picture rotation control)
万字讲清 synchronized 和 ReentrantLock 实现并发中的锁
随机推荐
Why is "iFLYTEK Super Brain 2030 plan" more worthy of expectation than "pure" virtual human
微服务开发环境搭建
[work notes] the problem of high leakage current in standby mode of dw7888 motor driver chip
[the second day of the actual combat of the smart lock project based on stm32f401ret6 in 10 days] light up with the key ----- input and output of GPIO
C language volatile learning
I didn't expect that the index occupies several times as much space as the data MySQL queries the space occupied by each table in the database, and the space occupied by data and indexes. It is used i
rsync 传输排除目录
Alertwindowmanager pop up prompt window help (Part 1)
[the 4th day of the 10 day smart lock project based on stm32f401ret6] what is interrupt, interrupt service function, system tick timer
(no plug-in) summary of vim basic shortcut keys
Répertoire d'exclusion du transport rsync
The execution results of i+=2 and i++ i++ under synchronized are different
What did Hello travel do right for 500million users in five years?
Delphi 10.4.2 release instructions and installation methods of three patches
移动IPv6光猫登录的一般ip地址账号与密码,移动光猫变桥接模式
uniapp 预览功能
Application and routine of C language typedef struct
DFS and BFS to solve Treasure Island exploration
Establishment of microservice development environment
Can't use typedef yet? C language typedef detailed usage summary, a solution to your confusion. (learning note 2 -- typedef setting alias)