当前位置:网站首页>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!↓↓↓↓↓↓"""边栏推荐
- [store mall project 01] environment preparation and testing
- 敏捷交付的工程效能治理
- Thinkphp commonly used techniques
- OpenCV如何实现Sobel边缘检测
- 小甲鱼汇编笔记
- 在Activity中获取另一个XML文件的控件
- Flask框架初学-05-命令管理Manager及数据库的使用
- Simple sorting (summer vacation daily question 14)
- Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
- 一个项目的整体测试流程有哪几个阶段?测试方法有哪些?
猜你喜欢

【store商城项目01】环境准备以及测试

2022 China Computing Power Conference released the excellent results of "Innovation Pioneer"

小甲鱼汇编笔记

redis中常见的问题(缓存穿透,缓存雪崩,缓存击穿,redis淘汰策略)

Use of lombok annotation @RequiredArgsConstructor

Example: 036 is a prime number

计算首屏时间

SAP SD module foreground operation

实例041:类的方法与变量

Slipper - virtual point, shortest path
随机推荐
LDO investigation
Android interview questions and answer analysis of major factories in the first half of 2022 (continuously updated...)
Use of lombok annotation @RequiredArgsConstructor
VR panorama shooting online exhibition hall, 3D panorama brings you an immersive experience
2022 China Computing Power Conference released the excellent results of "Innovation Pioneer"
pygame 中的transform模块
天地图坐标系转高德坐标系 WGS84转GCJ02
网页三维虚拟展厅为接入元宇宙平台做基础
哎,又跟HR在小群吵了一架!
Sticker Spelling - Memory Search / Shape Pressure DP
Summary of GNSS Articles
splice随机添加和删除的写法
appium软件自动化测试框架
ThreadLocal
【日志框架】
FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
idea中diagram使用
一篇文章看懂JS闭包,从执行上下文角度解析有趣的闭包
Is there any jdbc link to Youxuan database documentation and examples?
22/8/3(板子)树状dp板子+中国剩余定理+求组合数3,4+容斥原理