t = [ 3, 8, 2, 4, 5, 1, 6] osszeg = 0 for num in t: osszeg = osszeg + num print("Összeg: ", osszeg)
t = [ 3, 8, 2, 4, 5, 1, 6] count = 0 for num in t: if num > 5: count = count + 1 print("5-nél nagyobb: ", count)
t = [ 3, 8, 2, 4, 5, 1, 6] n = len(t) ker = 5 i = 0 while i < n and t[i] != ker: i = i + 1 if i<n: print("Van ilyen: ", ker) else: print("Nincs ilyen elem: ", ker)
t = [ 3, 8, 2, 4, 5, 1, 6] n = len(t) ker = 5 i = 0 while t[i] != ker: i = i + 1 print("Hányadik helyen van: ", i+1)
t = [ 3, 8, 2, 4, 5, 1, 6] n = len(t) ker = 5 i = 0 while i < n and t[i] != ker: i = i + 1 if(i < n): print('Van ' + str(ker) + ' elem') print("Helye: ", i+1) else: print('Nincs ' + str(ker) + ' elem!')
a = [ 3, 8, 2, 4, 5, 1, 6] b = [] def dupla(num): return num * 2 for elem in a: b.append(dupla(elem)) print(b)
a = [ 3, 8, 2, 4, 5, 1, 6] b = [] for elem in a: if elem < 5: b.append(elem) print(b)
a = [ 3, 8, 2, 4, 5, 1, 6] b = [] c = [] for elem in a: if elem < 5: b.append(elem) else: c.append(elem) print(b) print(c)
a = [ 5, 3, 6, 2, 1 ] b = [ 6, 2, 7, 8, 9 ] c = [] n = len(b) for elem in a: i = 0 while i < n and elem != b[i]: i+=1 if i<n: c.append(elem) print(c)
a = [ 5, 3, 6, 2, 1 ] b = [ 6, 2, 7, 8, 9 ] n = len(a) m = len(b) c = a.copy() for j in range(0, m): i=0 while i < n and b[j] != a[i]: i+=1 if i>=n: c.append(b[j]) print(c)
t = [ 5, 3, 6, 2, 1 ] maxElem = t[0] for elem in t: if elem > maxElem: maxElem = elem print(maxElem)
t = [ 5, 3, 6, 2, 1 ] minElem = t[0] for elem in t: if elem < minElem: minElem = elem print(minElem)
t = [ 5, 3, 6, 2, 1 ] n = len(t) for i in range(n-1, 0, -1): for j in range(0, i): if(t[j] > t[j+1]): tmp = t[j+1] t[j+1] = t[j] t[j] = tmp print(t)
t = [ 5, 3, 6, 2, 1 ] n = len(t) for i in range(0, n-1): for j in range(i+1, n): if(t[i] > t[j]): tmp = t[i] t[i] = t[j] t[j] = tmp print(t)
t = [ 5, 3, 6, 2, 1, 9 ] n = len(t) for i in range(n-1, -1, -1): maxIndex = i for j in range(0, i): if(t[j] > t[maxIndex]): maxIndex = j tmp = t[i] t[i] = t[maxIndex] t[maxIndex] = tmp print(t)
t = [ 5, 3, 6, 2, 1, 9 ] n = len(t) for i in range(0, n-2): minIndex = i for j in range(i+1, n-1): if(t[j] < t[minIndex]): minIndex = j if minIndex != i: tmp = t[i] t[i] = t[minIndex] t[minIndex] = tmp print(t)
t = [ 5, 3, 6, 2, 1, 9 ] n = len(t) for i in range(0, n): kulcs = t[i] j = i - 1 while j >= 0 and t[j] > kulcs: t[j+1] = t[j] j = j - 1 t[j+1] = kulcs print(t)
t = [ 5, 3, 6, 2, 1, 9 ] h = [5, 3, 1] n = len(t) for k in range(0, 3): lepes = h[k] for j in range(lepes, n): i = j - lepes kulcs = t[j] while i >= 0 and t[i] > kulcs: t[i+lepes] = t[i] i = i - lepes t[i+lepes] = kulcs print(t)
t = [ 5, 3, 6, 2, 1, 9 ] def gyorsrendezes(lista): meret = len(lista) if meret <= 1: return lista kicsik = [] egyenlo = [] nagyok = [] pivot = lista[meret-1] for num in lista: if num < pivot: kicsik.append(num) if num == pivot: egyenlo.append(num) if num > pivot: nagyok.append(num) return gyorsrendezes(kicsik) + egyenlo + gyorsrendezes(nagyok) print(gyorsrendezes(t))
#!/usr/bin/python # coding: utf8 def kiir(tomb, meret): for i in range(0, meret+1): print tomb[i] a = [2, 3, 7, 8] b = [3, 6, 9, 12, 18] c = [0] * 9 n = len(a) m = len(b) i = 0 j = 0 k = -1 while i<n and j<m : k+=1 if a[i]<b[j] : c[k] = a[i] i+=1 elif a[i] == b[j] : c[k] = a[i] i+=1 j+=1 elif a[i] > b[j] : c[k] = b[j] j+=1 while i<n : k+=1 c[k] = a[i] i+=1 while j<m : k+=1 c[k] = b[j] j+=1 kiir(c, k)