Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么系统只扫描第一个数字——Python来决定哪个更大_Python - Fatal编程技术网

为什么系统只扫描第一个数字——Python来决定哪个更大

为什么系统只扫描第一个数字——Python来决定哪个更大,python,Python,这是我的代码,当我输入数字时 两个数字和一个只有一个数字的数字, (例如,当我输入47、57和9时)结果为9 哪一个是最小的。请帮忙 def maximum(a, b, c): list = [a, b, c] return max(list) num_one = input("Enter 1st Number: ") num_two = input("Enter 2nd Number: ") num_three = i

这是我的代码,当我输入数字时 两个数字和一个只有一个数字的数字, (例如,当我输入47、57和9时)结果为9 哪一个是最小的。请帮忙

def maximum(a, b, c):
        list = [a, b, c]
        return max(list)


num_one = input("Enter 1st Number: ")
num_two = input("Enter 2nd Number: ")
num_three = input("Enter 3rd Number: ")
num4 = 0

if num_one.isdecimal():
    if num_one.isdecimal():
        if num_one.isdecimal():
            a = num_one
            b = num_two
            c = num_three
            print(maximum(a, b, c))
        else:
            print("wrong input")
    else:
        print("wrong input")
else:
    print("wrong input")
使用
input()
时,它会自动接收字符串。因此,您必须稍后将其转换为浮点或整数。此外,关键字
也很有用,而不是使用三个
if
语句:

def maximum(a, b, c):
    list = [a, b, c]
    return max(list)

num_one = input("Enter 1st Number: ")
num_two = input("Enter 2nd Number: ")
num_three = input("Enter 3rd Number: ")

if num_one.isdecimal() and num_two.isdecimal() and num_three.isdecimal():
    a = float(num_one)
    b = float(num_two)
    c = float(num_three)
    print(maximum(a, b, c))
else:
    print('Wrong input')

这回答了你的问题吗
input()
始终返回字符串。比较字符串是按字典顺序进行的,所以
“9”>“45”
确实是正确的…为什么要检查三次相同的条件?请尝试
打印(最大值(int(num_-one)、int(num_-two)、int(num_-three))
@Ivan如果他们只是执行
num_x=int(输入(…)操作,会更容易阅读
…值得注意的是,
max
只是内置
max
的一个不必要的包装。i、 e.做
max(a,b,c)
将完全一样,非常感谢!:D