当前位置:网站首页>Instance, 038: the sum of the diagonal matrix
Instance, 038: the sum of the diagonal matrix
2022-08-04 01:43:00 【Lazy laughing】
Title: Find the sum of the main diagonal elements of a 3*3 matrix.
Program Analysis: i and j are the same on the main diagonal
Code:
mat = [[1, 2, 3],[3, 4, 5],[4, 5, 6]]res = 0for i in range(len(mat)):print(i, i, ':', mat[i][i])res += mat[i][i]print('The main diagonal sum is: ', res)Results:

"""Problems encountered during study and no one answered?The editor has created a QQ group for Python learning and communication, and you can enter the officially recommended group by scanning the code below.Looking for like-minded friends to help each other, there are also good video learning tutorials and PDF e-books in the group!↓↓↓↓↓↓"""边栏推荐
猜你喜欢
随机推荐
Snake game bug analysis and function expansion
ASP.NET 获取数据库的数据并写入到excel表格中
DDTL:远距离的域迁移学习
FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
Multithreading JUC Learning Chapter 1 Steps to Create Multithreading
splice随机添加和删除的写法
Sky map coordinate system to Gaode coordinate system WGS84 to GCJ02
如何用C语言代码实现商品管理系统开发
Kubernetes:(九)coredns(浪不动了)
The idea of the diagram
简单排序(暑假每日一题 14)
lombok注解@RequiredArgsConstructor的使用
HBuilderX的下载安装和创建/运行项目
字符串变形
在Activity中获取另一个XML文件的控件
Example: 036 is a prime number
《Greenplum构建实时数据仓库实践》简介
Web APIs BOM- 操作浏览器:swiper 插件
nodejs安装及环境配置
优秀的测试/开发程序员,是怎样修炼的?步步为营地去执行......









