尝试拆开非序列的夹板(拆包非序列)

谁能告诉我这段代码有什么问题:

def greater(a,b):
    if a > b:
        return a
    return b

num1, num2 = int(input("enter two number : ").split(","))
print(f"bigger is :  {greater(num1,num2)}")


TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
评论
hehe
hehe

你有

  • input("enter two number : ") that values let's say 1,2
  • input("...").split(",") is now ['1', '2'] so a list of 2 string

  • int(['1', '2']) << you can't do that

You need to map each value to int

num1, num2 = map(int,input("enter two number : ").split(","))

还是做

values = input("enter two number : ").split(",")
num1, num2 = int(values[0], int(values[1])
点赞
评论