TIME NOW CALENDAR CONVERT LENGTH CONVERT TEMPERATURE DICTIONARIES, LISTS SCIENCE EDUCATION RELIGION WORK CALCULATOR CALCULATE LIFE

# Python 3 programming language, learn python, tutorial

ALL TOPICS

## Python 3. extentions, modules

1. Module file - module.py. The file is inthe same folder as hello.py file:
# Fibonacci numbers module

def fib(n):
# write Fibonacci series up to n
a, b = 0, 1
while b < n:
print(b, end=' ')
a, b = b, a+b
print()

def fib2(n):
# return Fibonacci series up to n
result = []
a, b = 0, 1
while b < n:
result.append(b)
a, b = b, a+b
return result

2. Import of module. hello.py file:
import module

print ( "module.fib: ") ;  module.fib(1000);

print ( "module.fib2: " ,  module.fib2(100));

print ("module name: "  ,  module.__name__);

Result:
module.fib:
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
module.fib2:  [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
module name:  module

3. More import examples. Importing names directly:
from module import fib, fib2

fib(500)

4. Full set of functions:
from module import *

fib(500)

Task 1. Please import two modules with overlapping functions. What will happen when calling these functions?

5. Exampe. The list contains the names of all the modules, variables and functions that are defined in a module:
import module, sys

print (dir(module))

print (dir(sys))

import sys

print (sys.path)

print (sys.path)

ALL TOPICS

 Vitalij:import winsoundimport timefor x in range(1,11): print("TURN ON SOUND") soundfile = "c:/Windows/Media/Windows Unlock.wav" winsound.PlaySound(soundfile, winsound.SND_FILENAME|winsound.SND_ASYNC) time.sleep(1)winsound.Beep(440, 500)winsound.Beep(440, 500)winsound.Beep(440, 500)winsound.Beep(349, 350)winsound.Beep(523, 150)winsound.Beep(440, 500)winsound.Beep(349, 350)winsound.Beep(523, 150)winsound.Beep(440, 1000)winsound.Beep(659, 500)winsound.Beep(659, 500)winsound.Beep(659, 500)winsound.Beep(698, 350)winsound.Beep(523, 150)winsound.Beep(415, 500)winsound.Beep(349, 350)winsound.Beep(523, 150)winsound.Beep(440, 1000)2015-11-18 11:40:07
 Andrius:1. def sum( arg1, arg2 ):   total = arg1 + arg2   return total----------------------------------------------------import modulearg1=int(input("Iveskite pirmaji nari: "))arg2=int(input("Iveskite antraji nari: "))print(module.sum(arg1,arg2))2.import osos.system('#pasirinkta spalva')2015-11-19 07:55:49