如何显示用户输入的最大值和最小值? [英] how to show the max and min from user input?

查看:75
本文介绍了如何显示用户输入的最大值和最小值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没关系

if xmin == 1:
  print(ymin)

我尝试使用max和min,但遇到类型错误,该错误是'int'对象不可迭代的.

I tried using the max and min but I get a typeerror which is 'int' object not iterable.

推荐答案

您不能将min()和max()与整数一起使用.试图问一个最小值或最大值是真的没有意义,因为计算机只能使用一个数字.您需要像这样将用户输入添加到列表中:

You cannot use min() and max() with integers. It really makes no sense trying to ask a minimum or maximum if computer only has one number to work with. You need to add user inputs into a list like so:

ages = []
ages.append(age)

完成此操作后,可以使用min()和max()方法:

After you've done this you can use min() and max() methods:

a = min(ages)

这篇关于如何显示用户输入的最大值和最小值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆