pythonExample100/JCP038.py

18 lines
384 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

'''
【程序38】
题目求一个3*3矩阵对角线元素之和
1.程序分析利用双重for循环控制输入二维数组再将a[i][i]累加后输出。
2.程序源代码:
'''
if __name__ == '__main__':
a = []
sum = 0.0
for i in range(3):
a.append([])
for j in range(3):
a[i].append(float(raw_input("input num:\n")))
for i in range(3):
sum += a[i][i]
print sum