From e17703da0c63b89625547ea38f0d276941db1abc Mon Sep 17 00:00:00 2001 From: Graheb Date: Tue, 13 Mar 2018 14:22:01 +0100 Subject: [PATCH 1/3] lesson2 --- .../lesson_02_flow_control/AddingFactorial.py | 11 +++++++++++ .../lesson_02_flow_control/BishopMoves.py | 9 +++++++++ .../lesson_02_flow_control/ChocolateBar.py | 16 ++++++++++++++++ .../lesson_02_flow_control/KnightMove.py | 12 ++++++++++++ .../lesson_02_flow_control/Ladder.py | 5 +++++ .../lesson_02_flow_control/LeapYear.py | 8 ++++++++ .../lesson_02_flow_control/LostCard.py | 11 +++++++++++ .../lesson_02_flow_control/QueenMove.py | 13 +++++++++++++ .../lesson_02_flow_control/TheNumberOfZeros.py | 8 ++++++++ .../lesson_02_flow_control/TheSecondMaximum.py | 14 ++++++++++++++ .../lesson_02_flow_control/factorial.py | 9 +++++++++ 11 files changed, 116 insertions(+) create mode 100644 students/Hebdowska_Grazyna/lesson_02_flow_control/AddingFactorial.py create mode 100644 students/Hebdowska_Grazyna/lesson_02_flow_control/BishopMoves.py create mode 100644 students/Hebdowska_Grazyna/lesson_02_flow_control/ChocolateBar.py create mode 100644 students/Hebdowska_Grazyna/lesson_02_flow_control/KnightMove.py create mode 100644 students/Hebdowska_Grazyna/lesson_02_flow_control/Ladder.py create mode 100644 students/Hebdowska_Grazyna/lesson_02_flow_control/LeapYear.py create mode 100644 students/Hebdowska_Grazyna/lesson_02_flow_control/LostCard.py create mode 100644 students/Hebdowska_Grazyna/lesson_02_flow_control/QueenMove.py create mode 100644 students/Hebdowska_Grazyna/lesson_02_flow_control/TheNumberOfZeros.py create mode 100644 students/Hebdowska_Grazyna/lesson_02_flow_control/TheSecondMaximum.py create mode 100644 students/Hebdowska_Grazyna/lesson_02_flow_control/factorial.py diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/AddingFactorial.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/AddingFactorial.py new file mode 100644 index 000000000..0ca0b5947 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/AddingFactorial.py @@ -0,0 +1,11 @@ +n = int(input('n: ')) + +k = 2 +fcn = 1 +adding = 1 +while k <= n: + fcn = fcn * k + k += 1 + adding = adding + fcn + +print(adding) diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/BishopMoves.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/BishopMoves.py new file mode 100644 index 000000000..6137546d4 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/BishopMoves.py @@ -0,0 +1,9 @@ +x1 = int(input('x1: ')) +y1 = int(input('y1: ')) +x2 = int(input('x2: ')) +y2 = int(input('y2: ')) + +if abs(x2 - x1) == abs(y2 - y1): + print('yes') +else: + print('no') diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/ChocolateBar.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/ChocolateBar.py new file mode 100644 index 000000000..d908046b6 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/ChocolateBar.py @@ -0,0 +1,16 @@ +import math +n = int(input('n: ')) +m = int(input('m: ')) +k = int(input('k: ')) + +if (n * m > k): + if (k >= n or k >= m): + if k % n == 0: + print('yes') + elif k % m == 0: + print('yes') + else: + print('no') + +else: + print('no') diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/KnightMove.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/KnightMove.py new file mode 100644 index 000000000..32cada1c2 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/KnightMove.py @@ -0,0 +1,12 @@ +import math +x1 = int(input('x1: ')) +y1 = int(input('y1: ')) +x2 = int(input('x2: ')) +y2 = int(input('y2: ')) + +if (abs(x2 - x1) == 2) and (abs(y2 - y1) == 1): + print('yes') +elif (abs(x2 - x1) == 1) and (abs(y2 - y1) == 2): + print('yes') +else: + print('no') diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/Ladder.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/Ladder.py new file mode 100644 index 000000000..0b29c09ea --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/Ladder.py @@ -0,0 +1,5 @@ +n = int(input('n: ')) +l = "" +for i in range(1,n + 1): + l = l + str(i) + print(l) diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/LeapYear.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/LeapYear.py new file mode 100644 index 000000000..662bdbeb1 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/LeapYear.py @@ -0,0 +1,8 @@ +y = int(input('year: ')) + +if y % 4 == 0 and y % 100 != 0: + print('leap') +elif y % 400 == 0: + print('leap') +else: + print('common') diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/LostCard.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/LostCard.py new file mode 100644 index 000000000..e0f321ff7 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/LostCard.py @@ -0,0 +1,11 @@ +N = int(input('N: ')) +l = [] + +for i in range(0,N - 1): + n = int(input('n: ')) + if (0 < n) and (n <= N): + l.append(n) + +for i in range(1,N + 1): + if i not in l: + print(i) diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/QueenMove.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/QueenMove.py new file mode 100644 index 000000000..c2f58be0d --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/QueenMove.py @@ -0,0 +1,13 @@ +x1 = int(input('x1: ')) +y1 = int(input('y1: ')) +x2 = int(input('x2: ')) +y2 = int(input('y2: ')) + +if abs(x2 - x1) == abs(y2 - y1): + print('yes') +elif x2 == x1: + print('yes') +elif y2 == y1: + print('yes') +else: + print('no') diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/TheNumberOfZeros.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/TheNumberOfZeros.py new file mode 100644 index 000000000..14a8367cc --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/TheNumberOfZeros.py @@ -0,0 +1,8 @@ +N = int(input('N: ')) +suma=0 +for i in range (0,N): + n = int(input('n: ')) + if n == 0: + suma += 1 + +print(suma) diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/TheSecondMaximum.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/TheSecondMaximum.py new file mode 100644 index 000000000..da684d631 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/TheSecondMaximum.py @@ -0,0 +1,14 @@ +m1 = n = int(input('N: ')) +m2 = 0 +while n != 0: + n = int(input('N: ')) + if m1 < n: + m2 = m1 + m1 = n + elif m2 < n and n < m1: + m2 = n + +print(m2) + + + diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/factorial.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/factorial.py new file mode 100644 index 000000000..376339f3b --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/factorial.py @@ -0,0 +1,9 @@ +n = int(input('n: ')) + +k = 2 +fcn = 1 +while k <= n: + fcn = fcn * k + k += 1 + +print(fcn) From 2797e34ae8de2bbaab9b432bf982d18b467f6dca Mon Sep 17 00:00:00 2001 From: Hebdowska Grazyna Date: Thu, 29 Mar 2018 13:30:47 +0200 Subject: [PATCH 2/3] I corrected ChocoladeBar I corrected errors and try to join two commits --- .../lesson_02_flow_control/ChocolateBar.py | 5 ++--- .../lesson_02_flow_control/KnightMove.py | 1 - .../lesson_02_flow_control/Ladder.py | 2 +- .../lesson_02_flow_control/LeapYear.py | 2 +- .../lesson_02_flow_control/LostCard.py | 18 +++++++++--------- .../lesson_02_flow_control/TheNumberOfZeros.py | 14 +++++++------- .../lesson_02_flow_control/TheSecondMaximum.py | 13 +++++-------- 7 files changed, 25 insertions(+), 30 deletions(-) diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/ChocolateBar.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/ChocolateBar.py index d908046b6..70b06bd6c 100644 --- a/students/Hebdowska_Grazyna/lesson_02_flow_control/ChocolateBar.py +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/ChocolateBar.py @@ -1,4 +1,3 @@ -import math n = int(input('n: ')) m = int(input('m: ')) k = int(input('k: ')) @@ -8,9 +7,9 @@ if k % n == 0: print('yes') elif k % m == 0: - print('yes') + print('yes') else: - print('no') + print('no') else: print('no') diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/KnightMove.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/KnightMove.py index 32cada1c2..2a192833d 100644 --- a/students/Hebdowska_Grazyna/lesson_02_flow_control/KnightMove.py +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/KnightMove.py @@ -1,4 +1,3 @@ -import math x1 = int(input('x1: ')) y1 = int(input('y1: ')) x2 = int(input('x2: ')) diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/Ladder.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/Ladder.py index 0b29c09ea..9677fb8f4 100644 --- a/students/Hebdowska_Grazyna/lesson_02_flow_control/Ladder.py +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/Ladder.py @@ -1,5 +1,5 @@ n = int(input('n: ')) l = "" -for i in range(1,n + 1): +for i in range(1, n + 1): l = l + str(i) print(l) diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/LeapYear.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/LeapYear.py index 662bdbeb1..84b2d870a 100644 --- a/students/Hebdowska_Grazyna/lesson_02_flow_control/LeapYear.py +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/LeapYear.py @@ -1,6 +1,6 @@ y = int(input('year: ')) -if y % 4 == 0 and y % 100 != 0: +if y % 4 == 0 and y % 100 != 0: print('leap') elif y % 400 == 0: print('leap') diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/LostCard.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/LostCard.py index e0f321ff7..eec49e87d 100644 --- a/students/Hebdowska_Grazyna/lesson_02_flow_control/LostCard.py +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/LostCard.py @@ -1,11 +1,11 @@ -N = int(input('N: ')) -l = [] +number = int(input('Number of card: ')) +card = [] -for i in range(0,N - 1): - n = int(input('n: ')) - if (0 < n) and (n <= N): - l.append(n) +for i in range(0, number - 1): + n = int(input('n: ')) + if (0 < n) and (n <= number): + card.append(n) -for i in range(1,N + 1): - if i not in l: - print(i) +for i in range(1, number + 1): + if i not in card: + print(i) diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/TheNumberOfZeros.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/TheNumberOfZeros.py index 14a8367cc..a064aa00b 100644 --- a/students/Hebdowska_Grazyna/lesson_02_flow_control/TheNumberOfZeros.py +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/TheNumberOfZeros.py @@ -1,8 +1,8 @@ -N = int(input('N: ')) -suma=0 -for i in range (0,N): - n = int(input('n: ')) - if n == 0: - suma += 1 +number = int(input('N: ')) +number_of_zeros = 0 +for i in range(0, number): + new_number = int(input('n: ')) + if new_number == 0: + number_of_zeros += 1 -print(suma) +print(number_of_zeros) diff --git a/students/Hebdowska_Grazyna/lesson_02_flow_control/TheSecondMaximum.py b/students/Hebdowska_Grazyna/lesson_02_flow_control/TheSecondMaximum.py index da684d631..ec5e881e0 100644 --- a/students/Hebdowska_Grazyna/lesson_02_flow_control/TheSecondMaximum.py +++ b/students/Hebdowska_Grazyna/lesson_02_flow_control/TheSecondMaximum.py @@ -1,14 +1,11 @@ -m1 = n = int(input('N: ')) +m1 = n = int(input('N: ')) m2 = 0 while n != 0: - n = int(input('N: ')) + n = int(input('N: ')) if m1 < n: - m2 = m1 - m1 = n + m2 = m1 + m1 = n elif m2 < n and n < m1: - m2 = n + m2 = n print(m2) - - - From 3c7459dfd59c41d17d959270238139f9957e5848 Mon Sep 17 00:00:00 2001 From: Hebdowska Grazyna Date: Wed, 18 Jul 2018 13:09:17 +0200 Subject: [PATCH 3/3] lesson13 one --- .../lesson_13/Selective_shallow_compare .py | 28 +++++ .../Hebdowska_Grazyna/lesson_13/circle.py | 109 ++++++++++++++++++ .../lesson_13/object_inspector_1.py | 21 ++++ .../lesson_13/object_inspector_2.py | 25 ++++ 4 files changed, 183 insertions(+) create mode 100644 students/Hebdowska_Grazyna/lesson_13/Selective_shallow_compare .py create mode 100644 students/Hebdowska_Grazyna/lesson_13/circle.py create mode 100644 students/Hebdowska_Grazyna/lesson_13/object_inspector_1.py create mode 100644 students/Hebdowska_Grazyna/lesson_13/object_inspector_2.py diff --git a/students/Hebdowska_Grazyna/lesson_13/Selective_shallow_compare .py b/students/Hebdowska_Grazyna/lesson_13/Selective_shallow_compare .py new file mode 100644 index 000000000..e2cd08255 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_13/Selective_shallow_compare .py @@ -0,0 +1,28 @@ +class Car: + + def __init__(self, name, colour, age): + self.name = name + self.colour = colour + self.age = age + + +def compare(object1, object2, atribute_names): + object1_atr = [] + object2_atr = [] + for i in atribute_names: + object1_atr.append(getattr(object1, i)) + object2_atr.append(getattr(object2, i)) + if object1_atr == object2_atr: + print("Atributes are equal") + else: + print("Atributes are not equal") + + +def main(): + auto1 = Car("fiat", "white", 2) + auto2 = Car("fiat", "red", 2) + compare(auto1, auto2, ["age", "colour"]) + + +if __name__ == '__main__': + main() diff --git a/students/Hebdowska_Grazyna/lesson_13/circle.py b/students/Hebdowska_Grazyna/lesson_13/circle.py new file mode 100644 index 000000000..3de49338f --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_13/circle.py @@ -0,0 +1,109 @@ +import math + + +class Point: + + def __init__(self, x, y): + self.x = x + self.y = y + + +class Circle: + + def __init__(self, center, radius): + self.center = center + self.radius = radius + + +class Rectangle: + + def __init__(self, one_corner, height, width): + self.one_corner = one_corner + self.height = height + self.width = width + + +def distance(point1, point2): + return math.sqrt((point1.x - point2.x) ** 2 + (point1.y - point2.y) ** 2) + + +def point_in_circle(circle, point): + if distance(circle.center, point) <= circle.radius: + return True + else: + return False + + +def corner_point(rectangle): + secound = Point + third = Point + fourth = Point + secound.x = rectangle.one_corner.x + secound.y = rectangle.one_corner.y + rectangle.height + third.x = rectangle.one_corner.x + rectangle.width + third.y = secound.y + fourth.x = third.x + fourth.y = rectangle.one_corner.y + return secound, third, fourth + + +def rect_in_circle(circle, rectangle): + p1 = rectangle.one_corner + p2, p3, p4 = corner_point(rectangle) + if distance(circle.center, p1) > circle.radius: + return False + elif distance(circle.center, p2) > circle.radius: + return False + elif distance(circle.center, p3) > circle.radius: + return False + elif distance(circle.center, p4) > circle.radius: + return False + else: + return True + + +def rect_circle_overlap(cicle, rectangle): + p1 = rectangle.one_corner + p2, p3, p4 = corner_point(rectangle) + if distance(cicle.center, p1) < cicle.radius: + return True + elif distance(cicle.center, p2) < cicle.radius: + return True + elif distance(cicle.center, p3) < cicle.radius: + return True + elif distance(cicle.center, p4) < cicle.radius: + return True + else: + return False + + +def main(): + circle_center = Point(150, 100) + circle = Circle(circle_center, 75) + one_corner = Point(1, 50) + rectangle = Rectangle(one_corner, 20, 50) + point = Point(9, 120) + if point_in_circle(circle, point): + print("the Point lies in" + " or on the boundary of the circle.") + else: + print("the Point doesn't lay" + " in or on the boundary of the circle.") + + if rect_in_circle(circle, rectangle): + print("the Rectangle lies entirely" + " in or on the boundary of the circle.") + else: + print("the Rectangle doesn't lay entirely" + " in or on the boundary of the circle.") + + if rect_circle_overlap(circle, rectangle): + print("some of the corners" + " of the Rectangle fall inside the circle") + else: + print("the corners of the Rectangle" + " are outside the circle") + + +if __name__ == '__main__': + main() diff --git a/students/Hebdowska_Grazyna/lesson_13/object_inspector_1.py b/students/Hebdowska_Grazyna/lesson_13/object_inspector_1.py new file mode 100644 index 000000000..f524849f0 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_13/object_inspector_1.py @@ -0,0 +1,21 @@ +class Car: + + def __init__(self, name, colour, age): + self.name = name + self.colour = colour + self.age = age + + +def create_dictionary(object): + new_dictionary = object.__dict__ + for i in new_dictionary.keys(): + print("key=", i, "value=", new_dictionary[i]) + + +def main(): + auto = Car("fiat", "white", 2) + create_dictionary(auto) + + +if __name__ == '__main__': + main() diff --git a/students/Hebdowska_Grazyna/lesson_13/object_inspector_2.py b/students/Hebdowska_Grazyna/lesson_13/object_inspector_2.py new file mode 100644 index 000000000..8b8d355b8 --- /dev/null +++ b/students/Hebdowska_Grazyna/lesson_13/object_inspector_2.py @@ -0,0 +1,25 @@ +class Car: + def __init__(self, name, colour, age): + self.name = name + self.colour = colour + self.age = age + + +def create_dictionary(object): + new_dictionary = object.__dict__ + for i in new_dictionary.keys(): + if isinstance(new_dictionary[i], int): + print("key=", i, "value=", new_dictionary[i]) + elif isinstance(new_dictionary[i], float): + print("key=", i, "value=", new_dictionary[i]) + elif isinstance(new_dictionary[i], str): + print("key=", i, "value=", new_dictionary[i]) + + +def main(): + auto = Car("fiat", "white", 2) + create_dictionary(auto) + + +if __name__ == '__main__': + main()