当前位置:网站首页>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
- Example 035: Setting the output color
- Continuing to pour money into commodities research and development, the ding-dong buy vegetables in win into the supply chain
- Summary of GNSS Articles
- 观察者模式
- 实例035:设置输出颜色
- nodejs安装及环境配置
- pygame 中的transform模块
- Kubernetes:(九)coredns(浪不动了)
- C语言:学生管理系统(链表版)
猜你喜欢
随机推荐
GNSS文章汇总
字符串变形
JS 从零教你手写节流throttle
Variable string
《Greenplum构建实时数据仓库实践》简介
多渠道打包
可变字符串
How to copy baby from Taobao (or Tmall store) through API interface to Pinduoduo interface code docking tutorial
实例038:矩阵对角线之和
- heavy OpenCV 】 【 mapping
Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
工程制图平面投影练习
企业虚拟偶像产生了实质性的价值效益
Use nodejs switch version (no need to uninstall and reinstall)
MySQL回表指的是什么
The idea of the diagram
boot issue
简单排序(暑假每日一题 14)
贪吃蛇游戏Bug解析及功能扩展
在Activity中获取另一个XML文件的控件






