Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What am I doing wrong? Can't call earlier functions

def addition(num1, num2):
    answerAdd=num1+num2
    print(answerAdd)
def subtraction(num1, num2):
    answerSub=num1-num2
    print(answerSub)
def main():
    num1=int(input('Enter the first number: '))
    num2=int(input('Enter the second number: '))
    print(addition, subtraction)
main()

I’ve tried renaming the call function and can’t get it to return the arithmetic,.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

A couple of problems:

  1. print and return are not interchangeable. When you need your function to return a value you use return, when you merely need it to print something than use print. Your first two functions should be returning the values they calculate so that your main() function can print() them.

  2. When calling your functions you have to give them values for the arguments you defined. Your addition and subtraction functions both have two arguments.


def addition(num1, num2):
    answerAdd=num1+num2
    #Problem 1: changed to `return`
    return answerAdd

def subtraction(num1, num2):
    answerSub=num1-num2
    #Problem 1: changed to `return`
    return answerSub

def main():
    num1=int(input('Enter the first number: '))
    num2=int(input('Enter the second number: '))
    #Problem 2: changed to send `num1` and `num2` as arguments to both functions
    print(addition(num1, num2), subtraction(num1, num2))

main()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading