-2

Is there a way to ask for user input while defining a function? for example here's a simple function:

def sum3(a,b,c):
    add=a+b+c
    return add

in the above code, is there a way I can ask the user to enter 3 numbers. say, when the program runs the user sees a prompt saying "please enter 3 numbers"

4

1 に答える 1

6
def sum3():
    print "Please enter three numbers:"
    a = input()
    b = input()
    c = input()
    return sum((a,b,c)) # a+b+c

print sum3() # asks for input then prints result.

注: 組み込みsum関数を使用します。

于 2012-10-06T09:30:05.910 に答える