当前位置:网站首页>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!↓↓↓↓↓↓"""
边栏推荐
猜你喜欢
JS 保姆级贴心,从零教你手写实现一个防抖debounce方法
静态/动态代理模式
一个注解替换synchronized关键字:分布式场景下实现方法加锁
JS 从零教你手写节流throttle
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
this巩固训练,从两道执行题加深理解闭包与箭头函数中的this
HBuilderX的下载安装和创建/运行项目
持续投入商品研发,叮咚买菜赢在了供应链投入上
Example: 036 is a prime number
敏捷交付的工程效能治理
随机推荐
The idea of the diagram
Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
安全至上:落地DevSecOps最佳实践你不得不知道的工具
Deng Qinglin, Alibaba Cloud Technical Expert: Best Practices for Disaster Recovery across Availability Zones and Multiple Lives in Different Locations on the Cloud
企业虚拟偶像产生了实质性的价值效益
Use nodejs switch version (no need to uninstall and reinstall)
FeatureNotFound( bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested:
持续投入商品研发,叮咚买菜赢在了供应链投入上
【虚拟户生态平台】虚拟化平台安装时遇到的坑
nodejs+npm的安装与配置
idea中diagram使用
【OpenCV】-重映射
Variable string
LDO investigation
【Untitled】
观察者模式
【虚拟化生态平台】虚拟化平台esxi挂载USB硬盘
【QT小记】QT中信号和槽的基本使用
Hey, I had another fight with HR in the small group!
JS 保姆级贴心,从零教你手写实现一个防抖debounce方法