当前位置:网站首页>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!↓↓↓↓↓↓"""边栏推荐
- DDTL: Domain Transfer Learning at a Distance
- Slipper —— 虚点,最短路
- Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
- 优秀的测试/开发程序员,是怎样修炼的?步步为营地去执行......
- HBuilderX的下载安装和创建/运行项目
- Hey, I had another fight with HR in the small group!
- Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
- SAP SD module foreground operation
- 持续投入商品研发,叮咚买菜赢在了供应链投入上
- Promise 解决阻塞式同步,将异步变为同步
猜你喜欢

优秀的测试/开发程序员,是怎样修炼的?步步为营地去执行......

企业虚拟偶像产生了实质性的价值效益

一篇文章看懂JS闭包,从执行上下文角度解析有趣的闭包

Array_Sliding window | leecode brushing notes

HBuilderX的下载安装和创建/运行项目

实例037:排序

Observability:你所需要知道的关于 Syslog 的一些知识

MySQL回表指的是什么

esp32发布机器人电池电压到ros2(micro-ros+CoCube)

Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
随机推荐
Variable string
什么是SVN(Subversion)?
可变字符串
Flink jdbc connector 源码改造sink之 clickhouse多节点轮询写与性能分析
LDO investigation
The idea of the diagram
C程序编译和预定义详解
Deng Qinglin, Alibaba Cloud Technical Expert: Best Practices for Disaster Recovery across Availability Zones and Multiple Lives in Different Locations on the Cloud
pygame 中的transform模块
boot issue
priority_queue元素为指针时,重载运算符失效
【虚拟化生态平台】虚拟化平台搭建
Use nodejs switch version (no need to uninstall and reinstall)
Snake game bug analysis and function expansion
- heavy OpenCV 】 【 mapping
C 学生管理系统 显示链表信息、删除链表
Flask框架初学-05-命令管理Manager及数据库的使用
《Greenplum构建实时数据仓库实践》简介
html select标签赋值数据库查询结果
SAP SD模块前台操作