1
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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks bro for solution, i'm begginner in python
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.