首页 > 解决方案 > from import python code doesn't work correctly

问题描述

I created a module as mathfunctions.py including four functions, then created another module in which call one function from mathfunctions.py through from...import code. When I run the second module, all four functions were executed.

my first module:

def add (x,y):
return x + y
x = int(input("Please Enter the first number:"))
y = int(input("Please Enter the second number:"))       
result = add (x,y)
print ("The result is:" , result)

def subtract (x,y):
return x - y
x = int(input("Please Enter the first number:"))
y = int(input("Please Enter the second number:"))       
result = subtract (x,y)
print ("The result is:" , result)

def multiply (x,y):
return x * y
x = int(input("Please Enter the first number:"))
y = int(input("Please Enter the second number:"))       
result = multiply (x,y)
print ("The result is:" , resudelt)

def division (x,y):
if y != 0:
    return x / y
else:
    print ("Please Enter the correct number:")
x = int(input("Please Enter the first number:"))
y = int(input("Please Enter the second number:"))       
result = division (x,y)
print ("The result is:" , result) 

my second module:

from mathfunctions import add
add (x,y)

标签: python-3.x

解决方案


推荐阅读