Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------------
- re z lekcji:
- import re
- l = "avf76bau789bu"
- num = re.findall(r'\d+', l)
- print(num)
- num = re.findall('a', l)
- print(len(num))
- num = re.findall(r'\D+', l)
- for i in num:
- if len(i)<4:
- print(i, end=' ')
- n = "dfdf.glh fdfdf.ty gkhkh.py mfmfm.mp asa.py"
- print("\n")
- num = n.split(" ")
- for i in num:
- if i.endswith(".py") == True:
- print(i, end=' ')
- -----------------------------------
- moje kody z lekcji:
- s = "qwertyuiopasdfghjkl"
- l = len(s)
- for i in range(0,l):
- print (s[l-i-1], end = "")
- lista = ['abcd', 786, 2.23, 'john', 70.2, 'abcd', 786, 2.23, 'john', 70.2, 'abcd', 786, 2.23, 'john', 70.2, 'abcd', 786, 2.23, 'john', 70.2]
- print (type(lista[i]))
- for i in range (0,19):
- if (type(lista[i]) is str):
- print (lista[i])
- lista2 = ['asah', 'ashhga', 'ahsa', 'ashia', 'ghasa', 'akusa', 'asya', 'aassa', 'dfvasa', 'adfvsa', 'asvfa', 'asadsf', 'adfsa', 'asda', 'assdga', 'afsa', 'asssa', 'afsa', 'dasa', 'assa']
- lista2.sort()
- print (lista2)
- def pierwszaFun ( str ):
- "Oto pierwsza funkcja"
- print ("Czesc, jestem pierwsza funkcja")
- print (str)
- return
- #wywolanie funkcji
- pierwszaFun("Czesc, milo mi")
- #wyswietlenie opisu funkcji
- print (pierwszaFun.__doc__)
- def pisanie(naz1, naz2, naz3):
- fo = open(naz1, 'r')
- x = fo.read()
- fo_2 = open(naz2, 'w+')
- fo_3 = open(naz3, 'w+')
- print(x)
- tab = x.split(" ")
- for i in tab:
- if ((int)(i) % 2) == 0:
- fo_2.write(i)
- fo_2.write(" ")
- else:
- fo_3.write(i)
- fo_3.write(" ")
- fo.close()
- fo_2.close()
- fo_3.close()
- pisanie("Liczby2.txt", "jeden.txt", "dwa.txt")
- def argum3(*num):
- "jeden arg wymagany, wiele dowolnych"
- sum = 0
- print ("Podales argumenty:")
- for i in num:
- print (i)
- sum = sum + i
- print ("Suma:",sum)
- return
- argum3(10, 5, 4, 6, 9)
- n = (int)(input("Wpisz n: "))
- fo = open('Liczby.txt', 'w+')
- for i in range( 0, n ):
- l = input()
- fo.write(l)
- fo.write(" ")
- #print ("Pisze do pliku...")
- #print ("--pozycja w pliku:",fo.tell())
- #fo.seek(0)
- #print ("--pozycja w pliku:",fo.tell())
- #str1 = fo.read()
- #print ("Przeczytalem z pliku:\n",str1)
- #print ("--pozycja w pliku:",fo.tell())
- #fo.seek(10)
- #print ("--pozycja w pliku:",fo.tell())
- #3str2 = fo.read(10)
- #print ("Przeczytalem z pliku 10 znakow:\n",str2)
- fo.close()
- '''
- '''
- class MyFirstClass: #deklaracja klasy
- 'To jest pierwsza klasa w Pythonie' #doc klasy
- def sayHello(self): #deklaracja metody
- print("Hello Pythoniku!!") #cialo metody
- mfc = MyFirstClass() #tworzenie instancji
- mfc.sayHello() #wywolanie metody
- class A:
- def __init__(self):
- self.x = " x - klasa A"
- self.z = " z - klasa A"
- def __str__(self):
- return "Jestem klasa A i mam sobie: " + self.x + self.z
- class C(A):
- def __init__(self):
- A.__init__(self)
- self.x = " x - klasa C"
- self.y = " y - klasa C"
- def __str__(self):
- s += "Jestem klasa C i mam sobie: " + self.x + self.y
- return s
- a = A()
- c = C()
- # kopia obiektu c i rzutowanie na klase A
- import copy
- b = copy.copy(c)
- b.__class__ = A
- for o in (a,b,c):
- print("*******")
- print(o)
- '''
- '''
- class Super:
- 'Jest to klasa nadrzędna'
- def method(self):
- print("jestem w Super.method")
- def delegate(self):
- self.action() #metoda oczekuje zdefiniowania
- class Inheritor(Super):
- 'dziedzic - dziedziczy wszystko po klasie Super i nic nie dodaje'
- pass
- class Replacer(Super):
- 'Calkowicie zamienia metode method'
- def method(self):
- print("jestem w Replacer.method")
- class Extender(Super):
- 'Rozszerza działanie metody method'
- def method(self):
- print("poczatek Extender.method")
- Super.method(self)
- print("koniec Extender.method")
- class Provider(Super):
- 'Dostarcza wymaganą implementację metody action'
- def action(self):
- print("Akcja!!")
- if __name__ == '__main__':
- for klass in (Super,Inheritor,Replacer,Extender,Provider):
- print('\n'+klass.__name__+" ")
- klass().method()
- if(klass.__name__ == "Provider"):
- klass().delegate()
- '''
- class Pair:
- def __init__(self, a, b):
- self.a = a
- self.b = b
- def operation(self):
- self.operation()
- class Greater(Pair):
- def __init__(self, a, b):
- Pair.__init__(self, a, b)
- def operation(self):
- print(max(self.a,self.b))
- g = Greater(3,5)
- g.operation()
- # class PozaZakresem(Exception):
- # def __str__(self):
- # return"Poza zakresem"
- # class Pomiar:
- # def __init__(self, dana):
- # self.dana = dana
- # if self.dana<-20 or self.dana>20:
- # raise PozaZakresem
- #p = Pomiar(20)
- class PozaZakresem(Exception):
- def __str__(self):
- return"Poza zakresem"
- class Pomiar:
- def __init__(self, dana):
- self.dana = dana
- if self.dana<-20 or self.dana>20:
- raise PozaZakresem
- fo = open('Pomiary.txt', 'w+')
- n = int(input("Podaj n:"))
- for i in range (0, n):
- l = int(input())
- try:
- p = Pomiar(l)
- fo.write(str(l))
- fo.write(" ")
- except:
- PozaZakresem
- ---------------------------
- rozwiązania Tomka:
- napis = input("Podaj napis: ")
- odkad = int(len(napis)/2)
- for i in range(odkad, len(napis)):
- print(napis[i], end='')
- 2 nie dziala
- plik = open("Calk.txt", "r+")
- line = plik.read()
- liczby = line.split()
- print(liczby)
- maksymalna = max(liczby)
- print("Max: ", maksymalna)
- 3
- class End:
- def __init__(self, napis, n):
- self.napis = napis
- self.n = n
- def last(self):
- for i in range(len(self.napis)-self.n, len(self.napis)):
- print(self.napis[i], end='')
- sprawdz = End("jakis", 3)
- sprawdz.last()
- 4
- class Mult5(Exception):
- def __str__(self):
- return "Liczba jest podzielna przez 5"
- class Data:
- def __init__(self, x):
- if x % 5 == 0:
- raise Mult5()
- try:
- sprobuj = Data(6)
- print("Nie jest podzielna przez 5")
- except Mult5 as m5:
- print(m5)
- -------------------------------
- rozwiązania Krystka:
- napis = input("Podaj ciag znakow: ")
- if len(napis) % 2 == 0:
- polowa = len(napis) // 2
- else:
- polowa = (len(napis) // 2) + 1
- for i in range(0, polowa):
- print(napis[i], end='')
- 2
- plik = open("Dane.txt", "r+")
- liczby = plik.read()
- listaLiczb = liczby.split(' ')
- suma = 0
- for i in listaLiczb:
- suma += int(i)
- print(suma)
- 3
- class Short:
- lancuch = ''
- liczba = 0
- def __init__(self, lancuch, liczba):
- self.lancuch = lancuch
- self.liczba = liczba
- def first(self):
- for i in range(0, self.liczba):
- print(self.lancuch[i], end='')
- prefiks = Short('Dziendobry', 5)
- prefiks.first()
- 4
- class Odd(Exception):
- def __str__(self):
- return "Liczba jest nieparzysta!"
- class Number:
- def __init__(self, liczba):
- if liczba % 2 != 0:
- raise Odd()
- try:
- Number(10)
- print("Success")
- Number(11)
- print("Success")
- except Odd as od:
- print(od)
- 5
- import re
- linia = input("Podaj linie tekstu: ")
- podciagi = re.findall(r"d.*r", linia)
- print(max(podciagi))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement