当前位置:网站首页>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

螺旋矩阵_数组 | leecode刷题笔记

esp32 releases robot battery voltage to ros2 (micro-ros+CoCube)

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

ASP.NET 获取数据库的数据并写入到excel表格中

Flask框架初学-05-命令管理Manager及数据库的使用

《Greenplum构建实时数据仓库实践》简介

Priority_queue element as a pointer, the overloaded operators

Example: 036 is a prime number
随机推荐
nodejs+express实现数据库mysql的访问,并展示数据到页面上
Priority_queue element as a pointer, the overloaded operators
Example 040: Reverse List
FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
flask框架初学-06-对数据库的增删改查
天地图坐标系转高德坐标系 WGS84转GCJ02
在Activity中获取另一个XML文件的控件
多渠道打包
内网穿透-应用
Slipper - virtual point, shortest path
Kubernetes:(十一)KubeSphere的介绍和安装(华丽的篇章)
nodejs 安装多版本 版本切换
通用的测试用例编写大全(登录测试/web测试等)
C 学生管理系统 显示链表信息、删除链表
【QT小记】QT中信号和槽的基本使用
2022 China Computing Power Conference released the excellent results of "Innovation Pioneer"
Download install and create/run project for HBuilderX
【OpenCV】-重映射
appium软件自动化测试框架
SAP SD module foreground operation