Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LAB 3------------------------------------------------
- # fragmenty dotyczące rozwiązania poszczególnych zadań proszę oddzielić odpowiednimi komentarzami
- from array import *
- ####################### ZADANIE 2
- tablica = array('u',[])
- ile=int(input("Ile znaków chcesz wpisać?"))
- i=0
- x=0
- while i <ile:
- print("Podaj znak:")
- x = input()
- tablica.append(x)
- i+=1
- print(tablica)
- print("wypisuje elementy tablicy w odwrotnej kolejności:")
- tablica.reverse()
- for i in tablica:
- print(i)
- ###################### ZADANIE 3
- import random
- print("Losowanie liczb:")
- tablica = array('f',[])
- file = open("result.txt", "w")
- i = 0
- while i<10:
- x= random.uniform(-5,5)
- tablica.append(x)
- i+=1
- file.write(str(tablica))
- file.close()
- ###################### ZADANIE 4
- from numpy import *
- tablica=zeros((5,5),longlong)
- tablica[0][0]=2
- tablica[0][1]=3
- tablica[0][2]=4
- tablica[0][3]=5
- tablica[0][4]=6
- for i in range (1,5):
- for j in range (0,5):
- tablica[i][j]=tablica[i-1][j]*tablica[i-1][j]
- print(tablica)
- ###################### ZADANIE 5
- def letter_count(sciezka_pliku):
- file = open(sciezka_pliku)
- text = file.read()
- slownik = {}
- for literka in text:
- if literka == " " or literka == ".":
- continue
- elif literka in slownik:
- slownik[literka] = slownik[literka] + 1
- else:
- slownik[literka] = 1
- print(slownik)
- file.close()
- letter_count("text.txt")
- LAB4 ----------------------------------------
- #zadanie 2
- x = int(input("Podaj x: "))
- lista = []
- for i in range(1,x+1):
- lista.append((lambda z: z ** 2)(i))
- print(lista)
- #zadanie 3
- nums = [1, 2, 3, 5, 8, 3, 0, 7]
- res = list(filter(lambda x: x>4,nums))
- print(res)
- #zadanie 4
- slowa = ['s', 'sp', 'spa', 'spam']
- def gen():
- yield slowa
- for i in gen():
- print(i)
- #zadanie 5
- def decor(func):
- def wrap():
- print("Równanie funkcji: x*3 + x*5")
- func()
- print("Wynik to: ", rownanie())
- return wrap
- #x = int(input("Podaj x: "))
- def rownanie():
- return x*3 + x*5
- deco = decor(rownanie)
- deco()
- #zadanie 6
- n = int(input("Podaj n: "))
- k = int(input("Podaj k: "))
- def newton(n,k):
- if k == 0 or k == n:
- return 1
- elif n > k and k > 0:
- return newton(n-1,k-1) + newton(n-1,k)
- else:
- return -1
- print(newton(n,k))
- #zadanie 7
- zbior = {2,3,0,4,3,2}
- zbior1 = {20,30,40,50}
- print(zbior)
- x = int(input("Podaj element, który chcesz dodać "))
- y = int(input("Podaj element, który chcesz usunac "))
- def operacje ():
- zbior.add(x)
- zbior.remove(y)
- return zbior
- def suma():
- return zbior | zbior1
- def wspolne():
- return zbior & zbior1
- def roznica():
- return zbior - zbior1
- def roznica_symetryczna():
- return zbior ^ zbior1
- print(operacje())
- print(suma())
- print(wspolne())
- print(roznica())
- print(roznica_symetryczna())
- LaB5 ----------------------------------------
- ########## ZADANIE 2
- class Student:
- def __init__(self, imie, nr_albumu):
- self.imie = imie
- self.nr_albumu = nr_albumu
- student1 = Student("Adam",98745)
- student2 = Student("Wiesław", 93813)
- student3 = Student("Józef", 23244)
- ########## ZADANIE 3
- class Osoba:
- def __init__(self,imie, nazwisko):
- self.imie = imie
- self.nazwisko = nazwisko
- class Student(Osoba):
- def __init__(self,imie, nazwisko, nr_index):
- self.imie = imie
- self.nazwisko = nazwisko
- self.nr_index = nr_index
- student1 = Student("Adam", "magiczny", 34343)
- student2 = Student("Kasia", "Swaczek", 31278)
- student3 = Student("Ewelina", "Stój", 97532)
- print(student1.imie, student1.nazwisko, student1.nr_index)
- print(student2.imie, student2.nazwisko, student2.nr_index)
- print(student3.imie, student3.nazwisko, student3.nr_index)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement