Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.45 KB | None | 0 0
  1. def add(a, b):
  2.     return a+b
  3.  
  4.  
  5. def subtract(a, b):
  6.     return a-b
  7.  
  8.  
  9. def divide(a, b):
  10.     return a/b
  11.  
  12.  
  13. def multiply(a, b):
  14.     return a*b
  15.  
  16. # print(divide(24, 3))
  17.  
  18. # z4 **********************************************
  19.  
  20. # from math import *
  21. # print(exp(10))
  22. # print(pow(log10(5 + pow(sin(8),2)), 1/6))
  23. # print(fabs(3.55))
  24. # print(fabs(4.8))
  25.  
  26. # z5 **********************************************
  27.  
  28. # name = "JAN"
  29. # surname = "KOWALSKI"
  30. # print(name.capitalize() + ' ' + surname.capitalize())
  31.  
  32. # z6 & z8 **********************************************
  33.  
  34. # song_text = "fas la la la fasf la la la la fasfa la la"
  35. # print(song_text.count('la'))
  36. # print(song_text.split())
  37.  
  38. # z7 ********************************************
  39.  
  40. # something = "kontakt"
  41. # print("Second letter: " + something[1] + ", Last letter: " + something[len(something)-1])
  42.  
  43. # z9 ****************************************
  44.  
  45. # text = "ddd"
  46. # flt = 3.2
  47. # hexx = hex(10)
  48. # print("String: %s, Float: %f, hex: %s" % (text, flt, hexx))
  49.  
  50. # z10 ******************
  51.  
  52. # movies = ["Batman", "Taken", "Superman", "Spiderman", "Django"]
  53. # print(movies)
  54. # movies.sort()
  55. # print(movies)
  56.  
  57. # z11 ************************
  58.  
  59. # from math import *
  60. # deg = [0, 30, 60, 90]
  61. # sinus = [sin(0), sin(pi/6), sin(pi/4),sin(pi/3), sin(pi/2)]
  62. # cosinus = [cos(0), cos(pi/6), cos(pi/4),cos(pi/3), cos(pi/2)]
  63. # tangent = [tan(0), tan(pi/6), tan(pi/4),tan(pi/3), "-"]
  64. # print(deg)
  65. # print(sinus)
  66. # print(cosinus)
  67. # print(tangent)
  68.  
  69. # z12 *******************************
  70.  
  71. # phrase = "asdm agsofg asfo asfo asfo asfjj asfoj asfojj ss"
  72. # words = phrase.split()
  73. # print(words)
  74.  
  75. # z13 *************************************
  76.  
  77. # names = {
  78. #     "anmier": "Andrzej mieraze",
  79. #     "kowal": "Jan Kowalski",
  80. # }
  81. # print(names["anmier"] + " " +  names["kowal"])
  82.  
  83. # z14 z15 z16 ********************************
  84.  
  85. # shortrcuts = {
  86. #     "zw": "zaraz wracam",
  87. #     "cb": "ciebie",
  88. # }
  89. # copied_shortcuts = shortrcuts
  90. # print(shortrcuts)
  91. # copied_shortcuts["ok"] = "okay"
  92. # print(copied_shortcuts)
  93. # print(len(copied_shortcuts))
  94.  
  95. # Z1 ##################################################
  96. # str = input("type something and i will count spaces")
  97. # print(str.count(" "))
  98.  
  99. # Z2 ##################################################
  100. # a = input("type 1st integer\n")
  101. # b = input("type 2nd integer\n")
  102. # print(f"{a}x{b} = {int(a)*int(b)}")
  103.  
  104. # Z3 ##################################################
  105. # b = input("type a number\n")
  106. # print(f"absolute value of {b} is {abs(int(b))}")
  107.  
  108. # Z5 ##################################################
  109. # a = int(input("type a \n"))
  110. # b = int(input("type b \n"))
  111. # c = int(input("type c \n"))
  112. # if a<=10 and a>=0 and (a>b or b>c):
  113. #     print("requirements met")
  114. # else:
  115. #     print("requirements not met")
  116.  
  117. # Z6 ##################################################
  118. # a = [1, 5, 10, 20, 15, 3, 22, 45, 50, 23]
  119. # for x in a:
  120. #     if x%5==0:
  121. #         print(x)
  122.  
  123. # Z7 ##################################################
  124. # a = [int(x) for x in input("put some numbers separated by space\n").split()]
  125. # for x in a:
  126. #     print(x*x)
  127.  
  128. # Z8 ################################################## XD
  129.  
  130. # Z9 ##################################################
  131. # a = input("type a large number and i will sum its digits\n")
  132. # sum = 0
  133. # for char in a:
  134. #     sum += int(char)
  135. # print(sum)
  136.  
  137. # Z10 ##################################################
  138. # sym = input("What symbol?\n")
  139. # a = int(input("How many rows?\n"))
  140. # i=1
  141. # while i<=a:
  142. #     print(sym*i)
  143. #     i += 1
  144.  
  145. # Z11 ##################################################
  146. # sym = input("What symbol?\n")
  147. # a = int(input("Height?\n"))
  148. # space = " "
  149. # x=a
  150. # i = []
  151. # i.append(x)
  152. # while x>0:
  153. #     x-=2
  154. #     i.append(x)
  155. #
  156. # i.sort()
  157. # for z in i:
  158. #         print(space * int((a-z)/2) + sym * z + space * int((a-z)/2))
  159. #
  160. # i.reverse()
  161. # del i[0]
  162. # for z in i:
  163. #         print(space*int((a-z)/2) + sym*z + space*int((a-z)/2))
  164.  
  165. # Z12 ##################################################
  166. # a = [x for x in range(1, 100, 1)]
  167. # i=0
  168. # while i<101:
  169. #     for x in a:
  170. #         print(f"{x}x{i}={x*i}")
  171. #
  172. #     i+=1
  173.  
  174. # Z14 ##################################################
  175. # import math
  176. # a = int(input("(sqrt) type an int\n"))
  177. # if a>=0:
  178. #     print(math.sqrt(a))
  179.  
  180. # Z15 ##################################################
  181. import math
  182. # a = input("number pls:\n")
  183. # try:
  184. #    val = int(a)
  185. # except ValueError:
  186. #    print("That's not an int!")
  187.  
  188. #z1 ############################################ zbiory range comprahensions
  189.  
  190. # a = [1/x for x in range(1, 11)]
  191. # b = [2**x for x in range(11)]
  192. # c = [x for x in b if x % 4 == 0] podzielne przez
  193. #
  194. # print(a)
  195. # print(b)
  196. # print(c)
  197.  
  198. #z2 ############################################ random losowe numery macierz array comprahensions
  199.  
  200. # import numpy
  201. # a = numpy.random.randint(0, 500,(4,4))
  202. # print(a)
  203. #
  204. # b = [a[x][x] for x in range(4)]
  205. # print(b)
  206.  
  207. #z3 ############################################ slownik dictionary comprahensions
  208.  
  209. # products = {
  210. #     "mango": "pcs",
  211. #     "pen": "pcs",
  212. #     "meat": "kg",
  213. #     "apples": "kg",
  214. #     "orange": "kg",
  215. #     "bike": "pcs",
  216. #     "carrots": "pcs",
  217. #     "broccoli": "pcs",
  218. # }
  219. #
  220. # only_pcs = [key for key, value in products.items() if value == "pcs"]
  221. # print(only_pcs)
  222.  
  223. #z4 ############################################
  224.  
  225. # def monotonicity(a):
  226. #     if a == 0:
  227. #         print("stala")
  228. #     elif a < 0:
  229. #         print("malejaca")
  230. #     else:
  231. #         print("rosnaca")
  232. #
  233. # monotonicity(0)
  234.  
  235. #z5 ############################################
  236.  
  237. # def lines(a1,a2):
  238. #     if a1 == a2:
  239. #             print("rownolegle")
  240. #     elif a1*a2 == -1:
  241. #             print("prostopadle")
  242. #     else:
  243. #         print("ani takie ani takie")
  244. #
  245. # lines(1,3)
  246.  
  247. #z6 ############################################
  248.  
  249. # import math
  250. #
  251. # def circle_radius(x=1, a=1, y=1, b=1):
  252. #     return math.sqrt((x + a)**2 + (y + b)**2)
  253. #
  254. # print(circle_radius(-5, 1, -3, 6))
  255.  
  256. #z7 ############################################
  257.  
  258. # import math
  259. #
  260. # def pitagoras(a=1, b=1):
  261. #     return math.sqrt(a**2 + b**2)
  262. #
  263. # print(pitagoras(3,4))
  264.  
  265. #z8 ############################################
  266.  
  267. # def sequence(a1 = 1, diff = 1, n = 10):
  268. #     result = a1
  269. #     nex = a1
  270. #     for x in range(n-1):
  271. #         nex += diff
  272. #         result += nex
  273. #
  274. #     return result
  275. #
  276. # print(sequence(1, 2, 5))
  277.  
  278. #1, 3, 5, 7, 9
  279.  
  280. #z9 ############################################
  281.  
  282. # def sequence_multiply(a1 = 1, diff = 1, n = 10):
  283. #     result = a1
  284. #     nex = a1
  285. #     for x in range(n-1):
  286. #         nex += diff
  287. #         result *= nex
  288. #
  289. #     return result
  290. #
  291. # print(sequence_multiply(1, 2, 5))
  292.  
  293. #z10 ########################################### hash dictionary slownik licz suma argument
  294.  
  295. def items_count(** hash):
  296.     result = 0
  297.     for key in hash:
  298.         result += hash[key]
  299.     return result
  300.  
  301. x = {
  302.     "ok": 10,
  303.     "co": 1,
  304.     "to": 13,
  305.     "jest": 10,
  306. }
  307.  
  308. print(items_count(**x))
  309.  
  310. #z11 ###########################################
  311.  
  312. import zespolone
  313.  
  314. zespolone.rzeczywista
  315.  
  316. #z12 ###########################################
  317.  
  318. #z1 ############################################
  319.  
  320. # file = open("liczb.txt", "w")
  321. # c = [x for x in range(100) if x % 4 == 0]
  322. # file.writelines(str(c))
  323. # file.close()
  324.  
  325. #z2 ############################################
  326.  
  327. # file = open("liczb.txt", "r")
  328. # numbers = file.readline()
  329. # file.close()
  330. #
  331. # print(numbers)
  332.  
  333. #z3 ############################################
  334.  
  335. # with open("liczb.txt", "w") as file:
  336. #         file.write("xD\n")
  337. #         file.write("co\n")
  338. #         file.write("sD\n")
  339. #
  340. # with open("liczb.txt", "r") as file:
  341. #     for line in file:
  342. #         print(line)
  343.  
  344.  
  345. #z4 ############################################
  346.  
  347. # class Shopping:
  348. #     def __init__(self, name, count, measure, price):
  349. #         self.name = name
  350. #         self.count = count
  351. #         self.measure = measure
  352. #         self.price = price
  353. #
  354. #     def product_info(self):
  355. #         print(f"This is {self.name}, count is {self.count}{self.measure} and its price is {self.price}")
  356. #
  357. #     def how_much(self):
  358. #         return f"{self.count} {self.measure}"
  359. #
  360. #     def cost_count(self, count):
  361. #         return self.price * count
  362. #
  363. # maslo = Shopping("Maslo", 10, "kg", 7)
  364. #
  365. # maslo.product_info()
  366. # print(maslo.how_much())
  367. # print(maslo.cost_count(12))
  368.  
  369. #z5 ############################################
  370.  
  371. # class Sequences:
  372. #     def __init__(self, *numbers):
  373. #         self.numbers = list(numbers)
  374. #
  375. #     def print_data(self):
  376. #         return self.numbers
  377. #
  378. #     def calc_numbers(self, a1, r, how_much):
  379. #         self.numbers = []
  380. #         for n in range(how_much):
  381. #             self.numbers.append(a1 + (n) * r)
  382. #
  383. #     def calc_sum(self):
  384. #         result = 0
  385. #         for x in self.numbers:
  386. #             result += x
  387. #         return result
  388. #
  389. # first = Sequences(3,4,2,1,2,3,4,2,3,2,3,2)
  390. # print(first.print_data())
  391. # first.calc_numbers(1, 2, 10)
  392. # print(first.print_data())
  393. # print(first.calc_sum())
  394.  
  395. #z6 ############################################
  396.  
  397. # class Words:
  398. #     def __init__(self, first, second):
  399. #         self.first = first
  400. #         self.second = second
  401. #
  402. #     def is_palindrome(self, word):
  403. #         if word == word[::-1]:
  404. #             return True
  405. #         return False
  406. #
  407. #     def is_metagram(self):
  408. #         same_char = False
  409. #         if len(self.first) != len(self.second):
  410. #             return False
  411. #         else:
  412. #             for x in range(len(self.first)):
  413. #                 if (self.first[x] == self.second[x]):
  414. #                     continue
  415. #                 elif same_char == True:
  416. #                     return False
  417. #                 else:
  418. #                     same_char = True
  419. #         return True
  420. #
  421. #     def is_anagram(self):
  422. #         frst = []
  423. #         scnd = []
  424. #         for x in self.first:
  425. #             frst.append(x)
  426. #
  427. #         for x in self.second:
  428. #             scnd.append(x)
  429. #
  430. #         frst.sort()
  431. #         scnd.sort()
  432. #
  433. #         for x in range(len(frst)):
  434. #             if frst[x] != scnd[x]:
  435. #                 return False
  436. #         return True
  437. #
  438. #     def print_words(self):
  439. #         print(f"{self.first} {self.second}")
  440. #
  441. # wooords = Words("jaak", "kaaj")
  442. # print(wooords.is_palindrome(wooords.second))
  443. # print(wooords.is_metagram())
  444. # print(wooords.is_anagram())
  445. # wooords.print_words()
  446.  
  447. # z7 ################################
  448.  
  449. class Robaczek:
  450.     def __init__(self, x, y, step):
  451.         self.x = x
  452.         self.y = y
  453.         self.step = step
  454.  
  455.     def up(self, step_count):
  456.         self.y += self.step * step_count
  457.  
  458.     def down(self, step_count):
  459.         self.y -= self.step * step_count
  460.  
  461.     def left(self, step_count):
  462.         self.x -= self.step * step_count
  463.  
  464.     def right(self, step_count):
  465.         self.x += self.step * step_count
  466.  
  467.     def where_am_i(self):
  468.         print(f"X: {self.x}, Y: {self.y}")
  469.  
  470. bug = Robaczek(0,0,1)
  471.  
  472. bug.up(1)
  473. bug.down(1)
  474. bug.left(1)
  475. bug.right(1)
  476. bug.up(1)
  477. bug.right(1)
  478. bug.up(1)
  479. bug.where_am_i()
  480.  
  481. # z1 ###########################################################################
  482. # class Material:
  483. #     def __init__(self, type, length, width):
  484. #         self.type = type
  485. #         self.length = length
  486. #         self. width = width
  487. #
  488. #     def show_name(self):
  489. #         print(f"{self.type}")
  490. #
  491. #
  492. # class Clothes(Material):
  493. #     def __init__(self, size, color, whose):
  494. #         self.size = size
  495. #         self.color = color
  496. #         self.whose = whose
  497. #
  498. #     def info(self):
  499. #         print(f"Size is {self.size}, it is {self.color} and it belongs to {self.whose}")
  500. #
  501. #
  502. # class Sweater(Clothes):
  503. #     def __init__(self, sweater_type):
  504. #         self.sweater_type = sweater_type
  505. #
  506. #     def info(self):
  507. #         print(f"It is {self.sweater_type}")
  508. #
  509. # wool = Material("wool", 20, 30)
  510. # silk = Material("silk", 10, 20)
  511. #
  512. # print(f"{wool.length}, {wool.type}, {wool.width}")
  513. # silk.show_name()
  514. #
  515. # tshirt = Clothes("XL", "blue", "John")
  516. # print(f"{tshirt.size}, {tshirt.color}, {tshirt.whose}")
  517. # tshirt.info()
  518. #
  519. # golf = Sweater("golf")
  520. # golf.info()
  521.  
  522. # z5 ###########################################################################
  523.  
  524. # class Wspak:
  525. #     """Iterator zwracający wartości w odwróconym porządku"""
  526. #     def __init__(self, data):
  527. #         self.data = data
  528. #         self.index = len(data)
  529. #     def __iter__(self):
  530. #         return self
  531. #     def __next__(self):
  532. #         if self.index == 0:
  533. #             raise StopIteration
  534. #         self.index = self.index - 1
  535. #         return self.data[self.index]
  536. #
  537. # a = Wspak([3,2,4,2,1,3,2,2,2,3,3,3,3,3,3,3,3])
  538. # it = iter(a)
  539. # print(next(it))
  540. # print(next(it))
  541. # print(next(it))
  542. # print(next(it))
  543. # print(next(it))
  544. # print(next(it))
  545. # print(next(it))
  546.  
  547.  
  548. # z6 ###########################################################################
  549.  
  550. class Even:
  551.     """Iterator zwracający wartości w odwróconym porządku"""
  552.     def __init__(self, data):
  553.         self.data = data
  554.         self.index = -1
  555.     def __iter__(self):
  556.         return self
  557.     def __next__(self):
  558.         if self.index == len(self.data):
  559.             raise StopIteration
  560.         self.index += 2
  561.         return self.data[self.index]
  562.  
  563. b = Even([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])
  564. it = iter(b)
  565. print(next(it))
  566. print(next(it))
  567. print(next(it))
  568. print(next(it))
  569. print(next(it))
  570. print(next(it))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement