Esempio n. 1
0
import mymodule2
import mymodule

print(mymodule.add(10, 20))
print(mymodule.subtract(10, 20))
print(mymodule.multiply(10, 20))
print(mymodule2.power(10, 20))
Esempio n. 2
0
import mymodule
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print(mymodule.add(a, b))
print(mymodule.subtract(a, b))
print(mymodule.multiply(a, b))
print(mymodule.divide(a, b))
Esempio n. 3
0
import mymodule
import mymodule2

connection = urllib.urlopen(
    "http://www.learnpython.org/en/Modules_and_Packages")
#print "result = " + str(connection.info())
print "result code = " + str(connection.geturl())

# To make your own module, you just need to create a file with the module name

# To import the module, just use import command and filename without the extension
# To use the functions in the module, use <modulename>.<functionname>
print "Magic number in the module: %d" % mymodule.magic_number

print mymodule.add(3, 4)
print mymodule.subtract(3, 4)
print mymodule.divide(3, 4)
print mymodule.multiply(3, 4)

# You can import one module inside the other
from mymodule2 import average

# mymodule2 loads mymodule. But we'd expect that mymodule is loaded only once.
# this should NOT print 2
print "Magic number in the module: %d" % mymodule.magic_number

list = [1, 2, 5, 7, 8, 10, 15, -3]
x = mymodule2.average(list)

print x