自己实现扫描全盘的函数
def scan_disk(dir):
global count,dir_count
if os.path.isdir(dir):
files = os.listdir(dir)
for file in files:
print(file)
dir_count += 1
if os.path.isdir(dir + os.sep + file):
scan_disk(file)
else:
count += 1
scan_disk("D:")
print("file_count",count)
print("dircount",count)
def is_zhishu(num):
for i in range(2, num // 2 + 1):
if num % i == 0:
return False
return True
def is_huiwenshu(num):
if str(num) == str(num)[::-1]:
return True
count = 0
num = 2
while count < 100:
if is_zhishu(num) and is_huiwenshu(num):
print("%5d" % num, end=" ")
count += 1
if count % 10 == 0:
print()
num += 1
def isValid(side1, side2, side3):
return side1 + side2 > side3 and side2 + side3 > side1 and side1 + side3 > side2
def area(side1, side2, side3):
s = (side1 + side2 + side3) / 2
return (s * (s - side1) * (s - side2) * (s - side3)) ** 0.5
s1, s2, s3 = eval(input("请输入三角形三边长:"))
if isValid(s1, s2, s3):
print("area is %.2f" % area(s1, s2, s3))
else:
print("Invalid")