Skip to content

Instantly share code, notes, and snippets.

View dencorg's full-sized avatar

Dennis Rodis dencorg

View GitHub Profile
@dencorg
dencorg / telnetgame.py
Last active August 29, 2015 14:18
Hacky Easter Egg 23
# coding=utf-8
import telnetlib
import json
from random import randint
def find_answer(question, data):
for entry in data:
if entry['question'] == question:
return entry['answer'].encode('utf-8')
data.append({'question': question, 'answer': ""})
@dencorg
dencorg / flattenizer.py
Created August 29, 2015 00:21
Flattenizer class test written in python. Flattens a list of integers.
# -*- coding: utf-8 -*-
# Flattenizer class
class Flattenizer:
"""Flattens a list of integers"""
def __init__(self, params):
if not isinstance(params, list):
raise ValueError('Argument is not a list')
elif len(params) == 0:
raise ValueError('List is empty')
@dencorg
dencorg / syntax.py
Last active October 20, 2017 09:32
# integers
one = 1
two = 2
some_number = 10000
# booleans
true_boolean = True
false_boolean = False
# string
2 + 2
# 4
50 - 5*6
# 20
(50 - 5*6) / 4
# 5.0
8 / 5
max = 10
x = 50
if x > max:
print('μεγαλύτερο')
else:
print('μικρότερο')
if x > max:
max = x
@dencorg
dencorg / loops.py
Last active October 20, 2017 11:17
num = int(input("X: "))
# έξοδος με μηδέν
while num != 0:
print(1/num)
num = int(input("X: "))
# έξοδος με break
while True:
num = int(input("X: "))
def add(a, b):
c = a + b
return c
print(add(2, 3))
def find_min(a,b):
if a < b:
return a
word = 'Python'
# ο πρώτος χαρακτήρας
print(word[0])
# ο δεύτερος χαρακτήρας
print(word[1])
print(word[2])
print(word[3])
@dencorg
dencorg / lists.py
Last active October 20, 2017 22:39
colors = ['red','green','blue', 'yellow']
a_list = [] # κενή λίστα
whatever = ['abc', 4.56, [2,3], 'def', 6]
print(whatever)
print(colors[0]) # 'red'
print(colors[1]) # 'green'
print(colors[-1]) # 'yellow'
@dencorg
dencorg / dicts.py
Last active October 20, 2017 23:14
prices = { 'milk': 3.67, 'bread': 1.67, 'cheese': 4.67 }
print(prices)
print(prices['milk'])
# προσθήκη ζεύγους κλειδιού τιμής
prices['butter'] = 1.95
# διαγραφή στοιχείου
del prices['butter']