This file contains 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
# 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': ""}) |
This file contains 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
# -*- 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') |
This file contains 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
# integers | |
one = 1 | |
two = 2 | |
some_number = 10000 | |
# booleans | |
true_boolean = True | |
false_boolean = False | |
# string |
This file contains 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
2 + 2 | |
# 4 | |
50 - 5*6 | |
# 20 | |
(50 - 5*6) / 4 | |
# 5.0 | |
8 / 5 |
This file contains 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
max = 10 | |
x = 50 | |
if x > max: | |
print('μεγαλύτερο') | |
else: | |
print('μικρότερο') | |
if x > max: | |
max = x |
This file contains 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
num = int(input("X: ")) | |
# έξοδος με μηδέν | |
while num != 0: | |
print(1/num) | |
num = int(input("X: ")) | |
# έξοδος με break | |
while True: | |
num = int(input("X: ")) |
This file contains 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 add(a, b): | |
c = a + b | |
return c | |
print(add(2, 3)) | |
def find_min(a,b): | |
if a < b: | |
return a |
This file contains 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
word = 'Python' | |
# ο πρώτος χαρακτήρας | |
print(word[0]) | |
# ο δεύτερος χαρακτήρας | |
print(word[1]) | |
print(word[2]) | |
print(word[3]) |
This file contains 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
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' |
This file contains 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
prices = { 'milk': 3.67, 'bread': 1.67, 'cheese': 4.67 } | |
print(prices) | |
print(prices['milk']) | |
# προσθήκη ζεύγους κλειδιού τιμής | |
prices['butter'] = 1.95 | |
# διαγραφή στοιχείου | |
del prices['butter'] |
OlderNewer