如何在函数中将逗号分隔数输入作为参数?

时间:2018-03-26 03:58:18

标签: python python-3.x parameter-passing

这是我写的代码

try:
    def max_of_n(*args):
        max = 1
        for x in args:
            if x > max:
                max = x
        return max
    print(max_of_n(int(x) for x in input("Enter the numbers whose max you want to find").split(","))

except:
    print("You have entered wrong input")

对于上面的代码,我收到的错误

Traceback (most recent call last):
  File "C:/Users/Akshay/PycharmProjects/CodeClubProjectsAboutMe/Trial.py", line 8, in <module>
    max_of_n(int(x) for x in input("Enter numbers").split(","))
  File "C:/Users/Akshay/PycharmProjects/CodeClubProjectsAboutMe/Trial.py", line 4, in max_of_n
    if x > max:
TypeError: '>' not supported between instances of 'generator' and 'int'

你能帮我吗? 主要问题是如何通过单独的输入来分配我的功能?

0 个答案:

没有答案