Skip to content

Instantly share code, notes, and snippets.

View dp-quant's full-sized avatar

Dmytro Podoprosvietov dp-quant

View GitHub Profile
import math
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
def print_me(name, *args, **kwargs):
print('n:', name)
for arg in args:
print('wild args:', arg)
for kwarg in kwargs:
print('wild kwargs key: ' + kwarg + ' value: ' + kwargs[kwarg])
print(args)
print(kwargs)
file = 'text.txt'
with open(file, 'w') as f:
f.write("Hello file world!")
tokens = None
with open(file, 'a+') as f:
print(f.read())
f.seek(0)
print(f.read())
def make_counter():
count = 0
def counter():
nonlocal count
print(count)
count += 1
return count
return counter
"""
Refactor given program code:
•Put reusable code into the functions:
•First - to calculate days in year
•Second – to decide which planet year is bigger
•Put orbital_radius and orbital_speed together in same data structure
"""
import math
import math
import sys
orbital_radius = {"Mercury": 58, "Venus": 108, "Earth": 150, "Mars": 228, "Jupiter": 778, "Saturn": 1429, "Uranus": 2871, "Neptune": 4504} # millions of kilometres
orbital_speed = {"Mercury": 47.87, "Venus": 35.02, "Earth": 29.78, "Mars": 24.13, "Jupiter": 13.07, "Saturn": 9.69, "Uranus": 6.81, "Neptune": 5.43} # kilometres per second
planet1 = input("Planet 1: ")
orbital_radius_1 = orbital_radius[planet1] * 1000000 # turning millions of kilometres to kilometres
orbital_speed_1 = orbital_speed[planet1]
@dp-quant
dp-quant / countries.py
Created January 14, 2019 18:05
Countries and Domains
countries = {
'Ukraine': 'UA',
'Canada': 'CA',
'United Kingdom': 'UK',
'United States': 'US',
'Germany': 'DE'
}
codes = {
'UA': 'Kiev',
@dp-quant
dp-quant / experiments.py
Created December 24, 2018 18:17
experiments
a = 2
if a > 0:
print('positive')
elif a < 0:
print('negative')
if a < -10:
pass
@dp-quant
dp-quant / factory.py
Last active December 19, 2018 17:41
Car Factory example
#Factory method
class Car:
_engine = 'v4'
@classmethod
def builds(cls):
return {
'Van': Van,
'Racecar': Racecar,
@dp-quant
dp-quant / building.py
Last active December 8, 2018 13:25
lab1 - oop
import math
class Building: # Class "Building" creation
OUT_OF_STOCK = 'out of stock'
WAREHOUSE = 'warehouse'
REMOTE = 'remote warehouse'
__allowed_materials = ('steel', 'stone', 'wood', 'glass')
material = None
color = None