Click here to Skip to main content
14,739,403 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my code
def introduction():
    print('this program will give you the result of multiplication, division and addition of two numbers')
def num1():
    n1=int(input('please enter th first no.'))
    return n1
def  num2():
    n2=int(input('please enter the first no.'))
    return n2
def a(num1,num2):
    get_sum=num1+num2
    return get_sum   
def pyt():
    introduction()
    #this will give you the two numbers
    number1=num1()
    number2=num2()
    a(number1,number2)
    print(a)
pyt()


What I have tried:

I searched in other online resources
Posted
Updated 21-Oct-20 22:24pm
v2
Comments
Patrice T 22-Oct-20 3:08am
   
What is the problem with your code ?

1 solution

[update, thanks to Richard]
There's nothing wrong with your program.
Actually there is an error in your code, as well spotted by Richard:
Quote:
a(number1,number2)
print(a)

Should be instead
result = a(number1,number2)
print(result)
[/update]

I would have written it this way
def introduction():
    print('this program will give you the result of multiplication, division and addition of two numbers')

def ask_num(prompt):
    n=int(input(prompt))
    return n

def add(num1,num2):
    result = num1 + num2
    return result

def pyt():
    introduction()
    #this will give you the two numbers
    number1 = ask_num( 'please enter the first no.')
    number2 = ask_num( 'please enter the second no.')
    result = add(number1, number2)
    print('the result is ' +  str(result))

pyt()

but it's just matter of taste.
   
v2
Comments
Richard MacCutchan 22-Oct-20 4:22am
   
+5. More than a matter of taste, your code works.
CPallini 22-Oct-20 4:34am
   
Thank you Richard, anyway the OP code works as well.
Richard MacCutchan 22-Oct-20 5:04am
   
No, the OP code prints the address of function a, not its result.
CPallini 22-Oct-20 5:21am
   
OOPS, I stand corrected!
Thank you, Richard.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900