Advertisement
Guest User

Untitled

a guest
May 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.90 KB | None | 0 0
  1. LAB 3------------------------------------------------
  2.  
  3. # fragmenty dotyczące rozwiązania poszczególnych zadań proszę oddzielić odpowiednimi komentarzami
  4.  
  5. from array import *
  6. ####################### ZADANIE 2
  7. tablica = array('u',[])
  8. ile=int(input("Ile znaków chcesz wpisać?"))
  9. i=0
  10. x=0
  11. while i <ile:
  12.     print("Podaj znak:")
  13.     x = input()
  14.     tablica.append(x)
  15.     i+=1
  16. print(tablica)
  17. print("wypisuje elementy tablicy w odwrotnej kolejności:")
  18. tablica.reverse()
  19. for i in tablica:
  20.     print(i)
  21.  
  22.    
  23. ###################### ZADANIE 3
  24. import random
  25. print("Losowanie liczb:")
  26. tablica = array('f',[])
  27. file = open("result.txt", "w")
  28. i = 0
  29. while i<10:
  30.     x= random.uniform(-5,5)
  31.     tablica.append(x)
  32.     i+=1
  33. file.write(str(tablica))
  34. file.close()
  35.  
  36.  
  37.  
  38. ###################### ZADANIE 4
  39. from numpy import *
  40. tablica=zeros((5,5),longlong)
  41. tablica[0][0]=2
  42. tablica[0][1]=3
  43. tablica[0][2]=4
  44. tablica[0][3]=5
  45. tablica[0][4]=6
  46. for i in range (1,5):
  47.     for j in range (0,5):
  48.         tablica[i][j]=tablica[i-1][j]*tablica[i-1][j]
  49. print(tablica)
  50.  
  51. ###################### ZADANIE 5
  52.  
  53. def letter_count(sciezka_pliku):
  54.     file = open(sciezka_pliku)
  55.     text = file.read()
  56.     slownik = {}
  57.     for literka in text:
  58.         if literka == " " or literka == ".":
  59.             continue
  60.         elif literka in slownik:
  61.             slownik[literka] = slownik[literka] + 1
  62.         else:
  63.             slownik[literka] = 1
  64.     print(slownik)
  65.  
  66.     file.close()
  67.  
  68.  
  69. letter_count("text.txt")
  70.  
  71.  
  72. LAB4 ----------------------------------------
  73.  
  74. #zadanie 2
  75. x = int(input("Podaj x: "))
  76.  
  77. lista = []
  78.  
  79. for i in range(1,x+1):
  80.     lista.append((lambda z: z ** 2)(i))
  81.  
  82. print(lista)
  83.  
  84. #zadanie 3
  85.  
  86. nums = [1, 2, 3, 5, 8, 3, 0, 7]
  87. res = list(filter(lambda x: x>4,nums))
  88. print(res)
  89.  
  90. #zadanie 4
  91.  
  92. slowa = ['s', 'sp', 'spa', 'spam']
  93.  
  94. def gen():
  95.         yield slowa
  96.  
  97. for i in gen():
  98.     print(i)
  99.  
  100. #zadanie 5
  101.  
  102. def decor(func):
  103.     def wrap():
  104.         print("Równanie funkcji: x*3 + x*5")
  105.         func()
  106.         print("Wynik to: ", rownanie())
  107.     return wrap
  108.  
  109. #x = int(input("Podaj x: "))
  110.  
  111. def rownanie():
  112.         return x*3 + x*5
  113.  
  114. deco = decor(rownanie)
  115. deco()
  116.  
  117. #zadanie 6
  118.  
  119. n = int(input("Podaj n: "))
  120. k = int(input("Podaj k: "))
  121.  
  122. def newton(n,k):
  123.     if k == 0 or k == n:
  124.         return 1
  125.     elif n > k and k > 0:
  126.         return newton(n-1,k-1) + newton(n-1,k)
  127.     else:
  128.         return -1
  129.  
  130. print(newton(n,k))
  131.  
  132. #zadanie 7
  133.  
  134. zbior = {2,3,0,4,3,2}
  135. zbior1 = {20,30,40,50}
  136. print(zbior)
  137.  
  138.  
  139. x = int(input("Podaj element, który chcesz dodać "))
  140. y = int(input("Podaj element, który chcesz usunac "))
  141.  
  142. def operacje ():
  143.     zbior.add(x)
  144.     zbior.remove(y)
  145.     return zbior
  146.  
  147. def suma():
  148.     return zbior | zbior1
  149.  
  150. def wspolne():
  151.     return zbior & zbior1
  152.  
  153. def roznica():
  154.     return zbior - zbior1
  155.  
  156. def roznica_symetryczna():
  157.     return zbior ^ zbior1
  158.  
  159. print(operacje())
  160. print(suma())
  161. print(wspolne())
  162. print(roznica())
  163. print(roznica_symetryczna())
  164.  
  165.  
  166. LaB5 ----------------------------------------
  167.  
  168. ########## ZADANIE 2
  169. class Student:
  170.     def __init__(self, imie, nr_albumu):
  171.         self.imie = imie
  172.         self.nr_albumu = nr_albumu
  173.  
  174. student1 = Student("Adam",98745)
  175. student2 = Student("Wiesław", 93813)
  176. student3 = Student("Józef", 23244)
  177.  
  178.  
  179. ########## ZADANIE 3
  180. class Osoba:
  181.     def __init__(self,imie, nazwisko):
  182.         self.imie = imie
  183.         self.nazwisko = nazwisko
  184.  
  185. class Student(Osoba):
  186.     def __init__(self,imie, nazwisko, nr_index):
  187.         self.imie = imie
  188.         self.nazwisko = nazwisko
  189.         self.nr_index = nr_index
  190.  
  191. student1 = Student("Adam", "magiczny", 34343)
  192. student2 = Student("Kasia", "Swaczek", 31278)
  193. student3 = Student("Ewelina", "Stój", 97532)
  194.  
  195. print(student1.imie, student1.nazwisko, student1.nr_index)
  196. print(student2.imie, student2.nazwisko, student2.nr_index)
  197. print(student3.imie, student3.nazwisko, student3.nr_index)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement