how this function is working without parameters?

Viewed 51
def add1():
    c=a+b
    print("sum is",c)

a=int(input("Enter a:"))
b=int(input("Enter b:"))
add1() 

the program is about adding two numbers. and displaying result. I took a and b input from the user, and directly called the function without passing arguments. its working. Could you please explain why this is workig?

I'm also confused when to use arguments and when not?

1 Answers

Variable a and b are global as they are not declared in any indent, so all your function does is add variable a and b if you named your variable any thing other than a it b it would not work

Related