¶

In [1]:
i=0
while(i<9):
    print i,
    i+=1
0 1 2 3 4 5 6 7 8

¶

In [2]:
stack = [3, 4, 5]
stack.append(6)
stack.pop()
Out[2]:
7

2¶

In [3]:
a = int(raw_input("Type value of A (0 - 1): "))
b = int(raw_input("Type value of B (0 - 1): "))
c = int(raw_input("Type value of C (0 - 1): "))
print "H exodos einai f =", max((1-a)*b*(1-c),a*(1-b)*c)
Type value of A (0 - 1): 1
Type value of B (0 - 1): 1
Type value of C (0 - 1): 1
H exodos einai f = 0

¶

In [4]:
def f(v):
    if (v==1): return 1
    elif (v%2==0): return f(v/2)+2
    else: return f(v-1)+1
f(7)
Out[4]:
7

¶

In [5]:
x=0
while ((x<1) or (x>10)):
    x=int(input("Give a positive number less than 10: "))
    if (x<1):
        print ("The number is not positive\n")
    elif (x>9):
        print("The number is not less than 10\n")
for c in range(x,10):
    print c,
Give a positive number less than 10: 5
5 6 7 8 9

¶

In [8]:
def mikos_odd(list):
    pl=0
    for i in range (len(list)):
        if (list[i] % 2):
            pl+=1
    return (pl)
mikos_odd([1,3,6,8,10])
Out[8]:
2

¶

In [7]:
text =input("dose alfarithmitiko")
pl=0 
pu=0
for i in range (len(text)):
    if (text[i]>='a' and text[i]<='z'):
        pl+=1
    elif (text[i]>='A' and text[i]<='Z'):
        pu+=1
print "Peza:",pl, "Kefalaia:", pu
dose alfarithmitiko"sdASD"
Peza: 2 Kefalaia: 3

5a¶

In [9]:
list=[]
x=int(input("Give a positive number: "))
numbers = range(1,x+1)
for item in numbers:
    list.append(item)
list
Give a positive number: 5
Out[9]:
[1, 2, 3, 4, 5]

5b¶

In [ ]:
a=[]
for i in range(20):
	a.append(int(raw_input("Type value: ")))
a.sort()
print a[0],a[1],a[2]

6a¶

In [10]:
def search(P, num):
    pos=-1
    for i in range(len(P)): 
        if (P[i] == num): 
            pos = i
    return (pos)
search([1,3,4,5,1],0)
Out[10]:
-1

6b¶

In [11]:
def histogram(s):
    s=str(s)
    d = dict()
    for c in s:
        if c not in d:
            d[c] = 1
        else:
            d[c] += 1
    return d
histogram(12341)
Out[11]:
{'1': 2, '2': 1, '3': 1, '4': 1}
In [ ]: