This is a simple program that adds two numbers but in two separate modules:
Main program :
import aritmetica as ar
print ("Introdusca 2 numeros para sumarlos ")
print ("Introdusca el primer numero : ")
num_a = int (input())
print ("")
print ("Introdusca el segundo numero : ")
num_b = int (input())
print ("")
suma_num = ar.suma(num_a,num_b)
print ("La suma total de los dos numeros es :")
print ("")
print (suma_num)
Arithmetic module :
def suma (num1,num2):
return num1+num2
So far so good. The program adds the two numbers perfectly.
But I also want to experiment with a function without parameters. I have tried to do it in the following way:
import aritmetica as ar
print ("Introdusca 2 numeros para sumarlos ")
print ("Introdusca el primer numero : ")
num_a = int (input())
print ("")
print ("Introdusca el segundo numero : ")
num_b = int (input())
print ("")
suma_num = ar.suma()# elimino los parametros
print ("La suma total de los dos numeros es :")
print ("")
print (suma_num)
Arithmetic module :
def suma():
numero = (num1 + num2)
return numero
and I get the following error:
NameError: name 'num1' is not defined
What is the error? Thanks in advance.