mirror of
http://hblu.top:3000/st2411020106/111.git
synced 2026-01-28 06:53:24 +08:00
54 lines
1.0 KiB
Python
54 lines
1.0 KiB
Python
"""
|
|
测试代码 - 包含多个常见错误和问题
|
|
"""
|
|
|
|
def calculate_average(numbers)
|
|
total = 0
|
|
count = 0
|
|
for num in numbers
|
|
total += num
|
|
count += 1
|
|
average = total / count
|
|
return average
|
|
|
|
def find_max(numbers):
|
|
max_value = 0
|
|
for num in numbers:
|
|
if num > max_value:
|
|
max_value = num
|
|
return max_value
|
|
|
|
def process_data(data):
|
|
result = []
|
|
for item in data:
|
|
if item > 0:
|
|
result.append(item * 2)
|
|
if item < 0:
|
|
result.append(abs(item))
|
|
return result
|
|
|
|
def create_user(name, age):
|
|
user = {
|
|
"name": name,
|
|
"age": age,
|
|
}
|
|
return user
|
|
|
|
def main():
|
|
numbers = [10, 20, -5, 30, 15, -10]
|
|
|
|
avg = calculate_average(numbers)
|
|
print("平均值:", avg)
|
|
|
|
max_num = find_max(numbers)
|
|
print("最大值:", max_num)
|
|
|
|
processed = process_data(numbers)
|
|
print("处理结果:", processed)
|
|
|
|
user = create_user("张三", 25)
|
|
print("用户信息:", user)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|