Merge branch 'stackex'
This commit is contained in:
commit
7954b49ce6
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from file2 import Message
|
||||
|
||||
""" Single variable importation example """
|
||||
|
||||
WORD_LIST = ["hello","bonjour","ola"]
|
||||
|
||||
Message(1)
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Single variable importation example
|
||||
|
||||
:Example:
|
||||
>>> MyMessage = Message(0)
|
||||
|
||||
>>> type(MyMessage)
|
||||
<class '__main__.Message'>
|
||||
>>> print(MyMessage)
|
||||
hello world
|
||||
>>> repr(MyMessage)
|
||||
"phrase: hello world|wl: ['hello', 'bonjour', 'ola']"
|
||||
"""
|
||||
|
||||
class Message:
|
||||
|
||||
def __init__(self, index):
|
||||
from file1 import WORD_LIST
|
||||
|
||||
self._phrase = WORD_LIST[index] + " world"
|
||||
self._word_list = WORD_LIST
|
||||
|
||||
def __repr__(self):
|
||||
return "phrase: {}|wl: {}".format(self._phrase, self._word_list)
|
||||
|
||||
def __str__(self):
|
||||
return self._phrase
|
||||
|
||||
if __name__ == "__main__":
|
||||
""" Starting doctests """
|
||||
import doctest
|
||||
doctest.testmod()
|
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env python2
|
||||
# by Daniel Rosengren, modified by e-satis
|
||||
# https://stackoverflow.com/a/1429145/6709630
|
||||
|
||||
import sys, time
|
||||
stdout = sys.stdout
|
||||
|
||||
BAILOUT = 16
|
||||
MAX_ITERATIONS = 1000
|
||||
|
||||
class Iterator(object) :
|
||||
|
||||
def __init__(self):
|
||||
|
||||
print 'Rendering...'
|
||||
for y in xrange(-39, 39):
|
||||
stdout.write('\n')
|
||||
for x in xrange(-39, 39):
|
||||
if self.mandelbrot(x/40.0, y/40.0) :
|
||||
stdout.write(' ')
|
||||
else:
|
||||
stdout.write('*')
|
||||
|
||||
|
||||
def mandelbrot(self, x, y):
|
||||
cr = y - 0.5
|
||||
ci = x
|
||||
zi = 0.0
|
||||
zr = 0.0
|
||||
|
||||
for i in xrange(MAX_ITERATIONS) :
|
||||
temp = zr * zi
|
||||
zr2 = zr * zr
|
||||
zi2 = zi * zi
|
||||
zr = zr2 - zi2 + cr
|
||||
zi = temp + temp + ci
|
||||
|
||||
if zi2 + zr2 > BAILOUT:
|
||||
return i
|
||||
|
||||
return 0
|
||||
|
||||
t = time.time()
|
||||
Iterator()
|
||||
print '\nPython Elapsed %.02f' % (time.time() - t)
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python2
|
||||
# by Daniel Rosengren, modified by e-satis
|
||||
"""
|
||||
Module doctring
|
||||
https://stackoverflow.com/a/1429145/6709630
|
||||
"""
|
||||
|
||||
|
||||
import time
|
||||
from sys import stdout
|
||||
|
||||
BAILOUT = 16
|
||||
MAX_ITERATIONS = 1000
|
||||
|
||||
def mandelbrot(dim_1, dim_2):
|
||||
"""
|
||||
function doc string
|
||||
"""
|
||||
cr1 = dim_1 - 0.5
|
||||
ci1 = dim_2
|
||||
zi1 = 0.0
|
||||
zr1 = 0.0
|
||||
|
||||
for i in xrange(MAX_ITERATIONS) :
|
||||
temp = zr1 * zi1
|
||||
zr2 = zr1 * zr1
|
||||
zi2 = zi1 * zi1
|
||||
zr1 = zr2 - zi2 + cr1
|
||||
zi1 = temp + temp + ci1
|
||||
|
||||
if zi2 + zr2 > BAILOUT:
|
||||
return i
|
||||
|
||||
return 0
|
||||
|
||||
def execute() :
|
||||
"""
|
||||
func doc string
|
||||
"""
|
||||
print 'Rendering...'
|
||||
for dim_1 in xrange(-39, 39):
|
||||
stdout.write('\n')
|
||||
for dim_2 in xrange(-39, 39):
|
||||
if mandelbrot(dim_1/40.0, dim_2/40.0) :
|
||||
stdout.write(' ')
|
||||
else:
|
||||
stdout.write('*')
|
||||
|
||||
|
||||
START_TIME = time.time()
|
||||
execute()
|
||||
print '\nPython Elapsed %.02f' % (time.time() - START_TIME)
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#https://stackoverflow.com/questions/48729156/how-to-share-values-between-functions-in-python
|
||||
|
||||
from random import randrange
|
||||
|
||||
a = 20
|
||||
b = 45
|
||||
|
||||
def function1():
|
||||
coin = randrange(0, 100)
|
||||
a2 = a + coin
|
||||
return a2
|
||||
|
||||
|
||||
def function2(coin):
|
||||
b2 = b + coin
|
||||
return b2
|
||||
|
||||
coin = function1() - a
|
||||
f2 = function2(coin)
|
||||
print("coin: {}".format(coin))
|
||||
print("f2: {}".format(f2))
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Author: freezed <freezed@users.noreply.github.com> 2018-02-19
|
||||
Version: 0.1
|
||||
Licence: `GNU GPL v3` GNU GPL v3: http://www.gnu.org/licenses/
|
||||
|
||||
Testing conditions in try/except statement
|
||||
|
||||
https://stackoverflow.com/questions/48864496/adding-if-statement-in-a-try-except-bloc
|
||||
"""
|
||||
# ? if user_select_map_id is int(): ?
|
||||
|
||||
DEBUG_MODE = [False, True]
|
||||
|
||||
for status in DEBUG_MODE:
|
||||
print("DEBUG_MODE: {}".format(status))
|
||||
number = input("Type a integer: ")
|
||||
try:
|
||||
number = int(number)
|
||||
except ValueError as except_detail:
|
||||
if status:
|
||||
print("ValueError: «{}»".format(except_detail))
|
||||
else:
|
||||
print("«{}» is not an integer".format(number))
|
||||
else:
|
||||
print("Your number {} is an integer".format(number))
|
Loading…
Reference in New Issue