1、现有100万行的交易数据文件tans amt.txt,每行显示1个交易金额(首行无字段信息),样例如下。数据文件存放在服务器g:\data目录。
203.4
95
-509
1800
请通过Python脚本,把最大和最小的交易金额通过print命令打印出来:
file_path = r'g:\data\tans_amt.txt'
# 打开文件并读取所有行
with open(file_path, 'r') as file:
lines = file.readlines()
# 将金额转换为浮点数,并找到最大和最小值
transaction_amounts = [float(line.strip()) for line in lines]
max_transaction_amount = max(transaction_amounts)
min_transaction_amount = min(transaction_amounts)
# 打印最大和最小交易金额
print("最大交易金额:", max_transaction_amount)
print("最小交易金额:", min_transaction_amount)
标签:面试题,transaction,min,Python,金额,amount,file,print
From: https://blog.csdn.net/weixin_53928514/article/details/137182130