Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add(a, b):
- return a+b
- def subtract(a, b):
- return a-b
- def divide(a, b):
- return a/b
- def multiply(a, b):
- return a*b
- # print(divide(24, 3))
- # z4 **********************************************
- # from math import *
- # print(exp(10))
- # print(pow(log10(5 + pow(sin(8),2)), 1/6))
- # print(fabs(3.55))
- # print(fabs(4.8))
- # z5 **********************************************
- # name = "JAN"
- # surname = "KOWALSKI"
- # print(name.capitalize() + ' ' + surname.capitalize())
- # z6 & z8 **********************************************
- # song_text = "fas la la la fasf la la la la fasfa la la"
- # print(song_text.count('la'))
- # print(song_text.split())
- # z7 ********************************************
- # something = "kontakt"
- # print("Second letter: " + something[1] + ", Last letter: " + something[len(something)-1])
- # z9 ****************************************
- # text = "ddd"
- # flt = 3.2
- # hexx = hex(10)
- # print("String: %s, Float: %f, hex: %s" % (text, flt, hexx))
- # z10 ******************
- # movies = ["Batman", "Taken", "Superman", "Spiderman", "Django"]
- # print(movies)
- # movies.sort()
- # print(movies)
- # z11 ************************
- # from math import *
- # deg = [0, 30, 60, 90]
- # sinus = [sin(0), sin(pi/6), sin(pi/4),sin(pi/3), sin(pi/2)]
- # cosinus = [cos(0), cos(pi/6), cos(pi/4),cos(pi/3), cos(pi/2)]
- # tangent = [tan(0), tan(pi/6), tan(pi/4),tan(pi/3), "-"]
- # print(deg)
- # print(sinus)
- # print(cosinus)
- # print(tangent)
- # z12 *******************************
- # phrase = "asdm agsofg asfo asfo asfo asfjj asfoj asfojj ss"
- # words = phrase.split()
- # print(words)
- # z13 *************************************
- # names = {
- # "anmier": "Andrzej mieraze",
- # "kowal": "Jan Kowalski",
- # }
- # print(names["anmier"] + " " + names["kowal"])
- # z14 z15 z16 ********************************
- # shortrcuts = {
- # "zw": "zaraz wracam",
- # "cb": "ciebie",
- # }
- # copied_shortcuts = shortrcuts
- # print(shortrcuts)
- # copied_shortcuts["ok"] = "okay"
- # print(copied_shortcuts)
- # print(len(copied_shortcuts))
- # Z1 ##################################################
- # str = input("type something and i will count spaces")
- # print(str.count(" "))
- # Z2 ##################################################
- # a = input("type 1st integer\n")
- # b = input("type 2nd integer\n")
- # print(f"{a}x{b} = {int(a)*int(b)}")
- # Z3 ##################################################
- # b = input("type a number\n")
- # print(f"absolute value of {b} is {abs(int(b))}")
- # Z5 ##################################################
- # a = int(input("type a \n"))
- # b = int(input("type b \n"))
- # c = int(input("type c \n"))
- # if a<=10 and a>=0 and (a>b or b>c):
- # print("requirements met")
- # else:
- # print("requirements not met")
- # Z6 ##################################################
- # a = [1, 5, 10, 20, 15, 3, 22, 45, 50, 23]
- # for x in a:
- # if x%5==0:
- # print(x)
- # Z7 ##################################################
- # a = [int(x) for x in input("put some numbers separated by space\n").split()]
- # for x in a:
- # print(x*x)
- # Z8 ################################################## XD
- # Z9 ##################################################
- # a = input("type a large number and i will sum its digits\n")
- # sum = 0
- # for char in a:
- # sum += int(char)
- # print(sum)
- # Z10 ##################################################
- # sym = input("What symbol?\n")
- # a = int(input("How many rows?\n"))
- # i=1
- # while i<=a:
- # print(sym*i)
- # i += 1
- # Z11 ##################################################
- # sym = input("What symbol?\n")
- # a = int(input("Height?\n"))
- # space = " "
- # x=a
- # i = []
- # i.append(x)
- # while x>0:
- # x-=2
- # i.append(x)
- #
- # i.sort()
- # for z in i:
- # print(space * int((a-z)/2) + sym * z + space * int((a-z)/2))
- #
- # i.reverse()
- # del i[0]
- # for z in i:
- # print(space*int((a-z)/2) + sym*z + space*int((a-z)/2))
- # Z12 ##################################################
- # a = [x for x in range(1, 100, 1)]
- # i=0
- # while i<101:
- # for x in a:
- # print(f"{x}x{i}={x*i}")
- #
- # i+=1
- # Z14 ##################################################
- # import math
- # a = int(input("(sqrt) type an int\n"))
- # if a>=0:
- # print(math.sqrt(a))
- # Z15 ##################################################
- import math
- # a = input("number pls:\n")
- # try:
- # val = int(a)
- # except ValueError:
- # print("That's not an int!")
- #z1 ############################################ zbiory range comprahensions
- # a = [1/x for x in range(1, 11)]
- # b = [2**x for x in range(11)]
- # c = [x for x in b if x % 4 == 0] podzielne przez
- #
- # print(a)
- # print(b)
- # print(c)
- #z2 ############################################ random losowe numery macierz array comprahensions
- # import numpy
- # a = numpy.random.randint(0, 500,(4,4))
- # print(a)
- #
- # b = [a[x][x] for x in range(4)]
- # print(b)
- #z3 ############################################ slownik dictionary comprahensions
- # products = {
- # "mango": "pcs",
- # "pen": "pcs",
- # "meat": "kg",
- # "apples": "kg",
- # "orange": "kg",
- # "bike": "pcs",
- # "carrots": "pcs",
- # "broccoli": "pcs",
- # }
- #
- # only_pcs = [key for key, value in products.items() if value == "pcs"]
- # print(only_pcs)
- #z4 ############################################
- # def monotonicity(a):
- # if a == 0:
- # print("stala")
- # elif a < 0:
- # print("malejaca")
- # else:
- # print("rosnaca")
- #
- # monotonicity(0)
- #z5 ############################################
- # def lines(a1,a2):
- # if a1 == a2:
- # print("rownolegle")
- # elif a1*a2 == -1:
- # print("prostopadle")
- # else:
- # print("ani takie ani takie")
- #
- # lines(1,3)
- #z6 ############################################
- # import math
- #
- # def circle_radius(x=1, a=1, y=1, b=1):
- # return math.sqrt((x + a)**2 + (y + b)**2)
- #
- # print(circle_radius(-5, 1, -3, 6))
- #z7 ############################################
- # import math
- #
- # def pitagoras(a=1, b=1):
- # return math.sqrt(a**2 + b**2)
- #
- # print(pitagoras(3,4))
- #z8 ############################################
- # def sequence(a1 = 1, diff = 1, n = 10):
- # result = a1
- # nex = a1
- # for x in range(n-1):
- # nex += diff
- # result += nex
- #
- # return result
- #
- # print(sequence(1, 2, 5))
- #1, 3, 5, 7, 9
- #z9 ############################################
- # def sequence_multiply(a1 = 1, diff = 1, n = 10):
- # result = a1
- # nex = a1
- # for x in range(n-1):
- # nex += diff
- # result *= nex
- #
- # return result
- #
- # print(sequence_multiply(1, 2, 5))
- #z10 ########################################### hash dictionary slownik licz suma argument
- def items_count(** hash):
- result = 0
- for key in hash:
- result += hash[key]
- return result
- x = {
- "ok": 10,
- "co": 1,
- "to": 13,
- "jest": 10,
- }
- print(items_count(**x))
- #z11 ###########################################
- import zespolone
- zespolone.rzeczywista
- #z12 ###########################################
- #z1 ############################################
- # file = open("liczb.txt", "w")
- # c = [x for x in range(100) if x % 4 == 0]
- # file.writelines(str(c))
- # file.close()
- #z2 ############################################
- # file = open("liczb.txt", "r")
- # numbers = file.readline()
- # file.close()
- #
- # print(numbers)
- #z3 ############################################
- # with open("liczb.txt", "w") as file:
- # file.write("xD\n")
- # file.write("co\n")
- # file.write("sD\n")
- #
- # with open("liczb.txt", "r") as file:
- # for line in file:
- # print(line)
- #z4 ############################################
- # class Shopping:
- # def __init__(self, name, count, measure, price):
- # self.name = name
- # self.count = count
- # self.measure = measure
- # self.price = price
- #
- # def product_info(self):
- # print(f"This is {self.name}, count is {self.count}{self.measure} and its price is {self.price}")
- #
- # def how_much(self):
- # return f"{self.count} {self.measure}"
- #
- # def cost_count(self, count):
- # return self.price * count
- #
- # maslo = Shopping("Maslo", 10, "kg", 7)
- #
- # maslo.product_info()
- # print(maslo.how_much())
- # print(maslo.cost_count(12))
- #z5 ############################################
- # class Sequences:
- # def __init__(self, *numbers):
- # self.numbers = list(numbers)
- #
- # def print_data(self):
- # return self.numbers
- #
- # def calc_numbers(self, a1, r, how_much):
- # self.numbers = []
- # for n in range(how_much):
- # self.numbers.append(a1 + (n) * r)
- #
- # def calc_sum(self):
- # result = 0
- # for x in self.numbers:
- # result += x
- # return result
- #
- # first = Sequences(3,4,2,1,2,3,4,2,3,2,3,2)
- # print(first.print_data())
- # first.calc_numbers(1, 2, 10)
- # print(first.print_data())
- # print(first.calc_sum())
- #z6 ############################################
- # class Words:
- # def __init__(self, first, second):
- # self.first = first
- # self.second = second
- #
- # def is_palindrome(self, word):
- # if word == word[::-1]:
- # return True
- # return False
- #
- # def is_metagram(self):
- # same_char = False
- # if len(self.first) != len(self.second):
- # return False
- # else:
- # for x in range(len(self.first)):
- # if (self.first[x] == self.second[x]):
- # continue
- # elif same_char == True:
- # return False
- # else:
- # same_char = True
- # return True
- #
- # def is_anagram(self):
- # frst = []
- # scnd = []
- # for x in self.first:
- # frst.append(x)
- #
- # for x in self.second:
- # scnd.append(x)
- #
- # frst.sort()
- # scnd.sort()
- #
- # for x in range(len(frst)):
- # if frst[x] != scnd[x]:
- # return False
- # return True
- #
- # def print_words(self):
- # print(f"{self.first} {self.second}")
- #
- # wooords = Words("jaak", "kaaj")
- # print(wooords.is_palindrome(wooords.second))
- # print(wooords.is_metagram())
- # print(wooords.is_anagram())
- # wooords.print_words()
- # z7 ################################
- class Robaczek:
- def __init__(self, x, y, step):
- self.x = x
- self.y = y
- self.step = step
- def up(self, step_count):
- self.y += self.step * step_count
- def down(self, step_count):
- self.y -= self.step * step_count
- def left(self, step_count):
- self.x -= self.step * step_count
- def right(self, step_count):
- self.x += self.step * step_count
- def where_am_i(self):
- print(f"X: {self.x}, Y: {self.y}")
- bug = Robaczek(0,0,1)
- bug.up(1)
- bug.down(1)
- bug.left(1)
- bug.right(1)
- bug.up(1)
- bug.right(1)
- bug.up(1)
- bug.where_am_i()
- # z1 ###########################################################################
- # class Material:
- # def __init__(self, type, length, width):
- # self.type = type
- # self.length = length
- # self. width = width
- #
- # def show_name(self):
- # print(f"{self.type}")
- #
- #
- # class Clothes(Material):
- # def __init__(self, size, color, whose):
- # self.size = size
- # self.color = color
- # self.whose = whose
- #
- # def info(self):
- # print(f"Size is {self.size}, it is {self.color} and it belongs to {self.whose}")
- #
- #
- # class Sweater(Clothes):
- # def __init__(self, sweater_type):
- # self.sweater_type = sweater_type
- #
- # def info(self):
- # print(f"It is {self.sweater_type}")
- #
- # wool = Material("wool", 20, 30)
- # silk = Material("silk", 10, 20)
- #
- # print(f"{wool.length}, {wool.type}, {wool.width}")
- # silk.show_name()
- #
- # tshirt = Clothes("XL", "blue", "John")
- # print(f"{tshirt.size}, {tshirt.color}, {tshirt.whose}")
- # tshirt.info()
- #
- # golf = Sweater("golf")
- # golf.info()
- # z5 ###########################################################################
- # class Wspak:
- # """Iterator zwracający wartości w odwróconym porządku"""
- # def __init__(self, data):
- # self.data = data
- # self.index = len(data)
- # def __iter__(self):
- # return self
- # def __next__(self):
- # if self.index == 0:
- # raise StopIteration
- # self.index = self.index - 1
- # return self.data[self.index]
- #
- # a = Wspak([3,2,4,2,1,3,2,2,2,3,3,3,3,3,3,3,3])
- # it = iter(a)
- # print(next(it))
- # print(next(it))
- # print(next(it))
- # print(next(it))
- # print(next(it))
- # print(next(it))
- # print(next(it))
- # z6 ###########################################################################
- class Even:
- """Iterator zwracający wartości w odwróconym porządku"""
- def __init__(self, data):
- self.data = data
- self.index = -1
- def __iter__(self):
- return self
- def __next__(self):
- if self.index == len(self.data):
- raise StopIteration
- self.index += 2
- return self.data[self.index]
- b = Even([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])
- it = iter(b)
- print(next(it))
- print(next(it))
- print(next(it))
- print(next(it))
- print(next(it))
- print(next(it))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement