alpha
alpha

Reputation: 11

how this function is working without parameters?

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?

Upvotes: 1

Views: 118

Answers (1)

Crypto
Crypto

Reputation: 371

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

Upvotes: 1

Related Questions