体重比较器 - 轻松找出最重的人
使用 Python 编程可以轻松实现体重比较器的功能。以下是示例代码:
def compare_weight():
names = []
weights = []
for i in range(3):
name = input('请输入第{}个人的名字:'.format(i+1))
weight = float(input('请输入{}的体重(kg):'.format(name)))
names.append(name)
weights.append(weight)
max_weight = max(weights)
max_index = weights.index(max_weight)
max_name = names[max_index]
print('最重的人是{}, 体重为{}公斤。'.format(max_name, max_weight))
compare_weight()
运行程序后,根据提示输入三个人的名字和体重,程序会自动比较并找出最重的人的姓名和体重,并输出最重人的姓名和体重信息。
原文地址: https://www.cveoy.top/t/topic/qxNx 著作权归作者所有。请勿转载和采集!