This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def factorial(n): | |
if n == 0: | |
return 1 | |
else: | |
return n * factorial(n-1) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_counter(): | |
count = 0 | |
def counter(): | |
nonlocal count | |
print(count) | |
count += 1 | |
return count | |
return counter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
countries = { | |
'Ukraine': 'UA', | |
'Canada': 'CA', | |
'United Kingdom': 'UK', | |
'United States': 'US', | |
'Germany': 'DE' | |
} | |
codes = { | |
'UA': 'Kiev', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = 2 | |
if a > 0: | |
print('positive') | |
elif a < 0: | |
print('negative') | |
if a < -10: | |
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Factory method | |
class Car: | |
_engine = 'v4' | |
@classmethod | |
def builds(cls): | |
return { | |
'Van': Van, | |
'Racecar': Racecar, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |