# python 练习2020/10/26

习题8:两个 3 行 3列的矩阵，实现其对应位置的数据相加，并返回一个矩阵
x = [ [12,7,3], [4, 5,6], [7 ,8,9] ]
y = [ [5,8,1], [6, 7,3], [4 ,5,9] ]
result=x
for i in range(len(x)):
for j in range(len(x[i])):
result[i][j]+=y[i][j]
print(result)

#2
x = [ [12,7,3], [4, 5,6], [7 ,8,9] ]
y = [ [5,8,1], [6, 7,3], [4 ,5,9] ]
result=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(len(x)):
for j in range(len(x[i])):
result[i][j]=x[i][j]+y[i][j]

print(result)

import sys
letter_count=0
for i in sys.argv[1:]:#通过命令行传参，第一个是程序的名字，后面的才是传的参数
for j in i:
letter_count+=1

print(letter_count)

import sys

count=0
for i in sys.argv[1:]:
count+=float(i)

print(count)

while True:
try:
input_number=input('请输入一个数字:')
if input_number.isdigit():
break
except:
continue
#2
while True:
try:
number = int(input("请输入一个数字: "))
except:
print("try again")
else:
break

import os
import sys
count_dirs=0
count_files=0
count_code_line=0
count_comment_line=0
count_blank_line=0#可以用i.strip()or i.split()
if os.path.exists(sys.argv[1]):
for root,dirs,files in os.walk(sys.argv[1]):
for dir in dirs:
count_dirs+=1
for file in files:
count_files+=1
file_path=os.path.join(root,file)
with open(file_path,'r',encoding='utf-8')as fp:
for line in content:
if line.strip()=='':#判断空行
count_blank_line+=1
elif line.strip().startswith('#'):#判断是不是注释
count_comment_line+=1
elif line.strip().startswith('"""') or line.strip().startswith("'''"): #判断是不是多行注释
count_comment_line+=1
else:
count_code_line+=1

print('一共有%s目录'%count_dirs)
print('一共有%s文件'%count_files)
print('一共有%s有效代码行'%count_code_line)
print('一共有%s空行'%count_blank_line)
print('一共有%s注释行'%count_comment_line)

1、实现自己的数学模块mymath，提供有4个函数，分别为加减乘除，在B模块中调用A模块的函数。
result=0
for num in args:
result+=num
return result

from a import *

##################
def sub(a,b,*args):
number=a-b
for num in args:
number-=num
return number

from a import *
print(sub(9,2,3,1))

#####################
def mul(a,b,*args):
number=a*b
for i in args:
number*=i
return number

from a import *
print(mul(1,2,3,4))

###############
def div(a,b,*args):
number=a/b
for i in args:
number/=i
return number

from a import *
print(div(4,2,1))