20230917-Python基础

20230917-Python基础
词典文件:
dict.txt (1.9 MB)

教程地址:
https://tutorial.ceba.ceshiren.com/python_programming/v2/L1/tutorial/初识Python/

实战练习一:

"""
__author__ = '霍格沃兹测试开发学社'
__desc__ = '更多测试开发技术探讨,请访问:https://ceshiren.com/t/topic/15860'
"""
# 从键盘输入任意数量的数字,进行求和运算,123,abc, 输入=结束输入,输出结果

# 保存结果的变量
result = 0
max_value = None
min_value = None

while True:
    num = input("输入一个数字:")
    if num == "=":
        break
    elif num.isdigit():
        num = int(num)
        result += num
        if max_value == None:
            max_value = num
        if min_value == None:
            min_value = num

        # 转换的数字进行比较记录
        if max_value < num:
            max_value = num
        if min_value > num:
            min_value = num



print(f"结果是:{result}")
print(f"最大值 : {max_value}")
print(f"最小值 : {min_value}")

# nums = [-987871,3,5,4,2,34,7,773,4345,5476,6897,432]

实战练习二:

下载前的Dict.txt

实现英汉词典解析、

# 从文件中读取内容的方式

with open("dict.txt","r") as file:
      content = file.read()

print(content)