0

I have written some python code but this is not giving me any output please help me to solve.

def main():
    num1 = int(raw_input("Enter first number"))
    num2 = int(raw_input("Enter second number"))

    result = num1 + num2

    print result
2
  • 2
    Do you ever call that function? Add main() at the end. And see e.g. sopython.com/wiki/What_tutorial_should_I_read%3F Commented Sep 2, 2017 at 9:05
  • call the damn function to run it Commented Sep 2, 2017 at 9:09

2 Answers 2

2

You haven't called the function that you have created.

This will work:

def main():
    num1 = int(raw_input("Enter first number"))
    num2 = int(raw_input("Enter second number"))

    result = num1 + num2

    print result

main()

If this doesn't work then you are probably using python3, in that case try this:

def main():
    num1 = input("Enter first number")
    num2 = input("Enter second number")

    result = num1 + num2

    print (result)

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

Comments

2

Try calling the main() function:

def main():
    num1 = int(raw_input("Enter first number"))
    num2 = int(raw_input("Enter second number"))

    result = num1 + num2

    print result

main() # <-- calling main() function

Comments

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.