From: Nils Date: Mon, 4 Apr 2022 16:51:57 +0000 (+0200) Subject: push X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=c248f82890db6998ff4ac399741b4b3ac50420d2;p=TDDE44.git push --- diff --git a/laboration4/uppgift_3.py b/laboration4/uppgift_3.py index 458a41d..59226d4 100644 --- a/laboration4/uppgift_3.py +++ b/laboration4/uppgift_3.py @@ -7,13 +7,14 @@ import matplotlib import matplotlib.pyplot as plt import sys + # Mainloop def main(): - + # matplotlib setup matplotlib.use("AGG") plt.figure() - + # Accept multiple csv-files arg_len = len(sys.argv) - 1 csv_files = list() @@ -29,7 +30,7 @@ def main(): # Adds labels and info about current functions plt.xlabel("Dagar") plt.ylabel("Antal koppar") - plt.legend(loc='upper left', bbox_to_anchor=(1, 0, 1, 1)) + plt.legend(loc="upper left", bbox_to_anchor=(1, 0, 1, 1)) plt.savefig(__file__[0:-3] + ".png", bbox_inches="tight") diff --git a/laboration5/__pycache__/klasser.cpython-39.pyc b/laboration5/__pycache__/klasser.cpython-39.pyc new file mode 100644 index 0000000..c39acec Binary files /dev/null and b/laboration5/__pycache__/klasser.cpython-39.pyc differ diff --git a/laboration5/basics.py b/laboration5/basics.py new file mode 100644 index 0000000..897b2e7 --- /dev/null +++ b/laboration5/basics.py @@ -0,0 +1,31 @@ +class Contact: + def __init__(self, name): + self.name = name + self.phone_num = "" + + def append_to_name(self, string_to_append): + self.name += string_to_append + + def __str__(self): + return "{}, {}".format(self.name, self.phone_num) + + def __myMethod__(self): + print("hello") + + +c1 = Contact("Nils") +c2 = Contact("Lukas") +c3 = Contact("Pisse") + +c1.phone_num = "0701-111111" +c2.phone_num = "0702-222222" +c3.phone_num = "0703-333333" + +c1.append_to_name(" Forssen") +c2.append_to_name(" Eliasson") +c3.append_to_name(" Sjögren") + +contact_list = [c1, c2, c3] + +for contact in contact_list: + print(contact) diff --git a/laboration5/klasser.py b/laboration5/klasser.py new file mode 100644 index 0000000..6092d10 --- /dev/null +++ b/laboration5/klasser.py @@ -0,0 +1,19 @@ +class Pet: + def __init__(self, name=""): + self.kind = "" + self.toys = [] + self.name = name + + def add_toy(self, toy): + if toy not in self.toys: + self.toys.append(toy) + + def __str__(self): + if len(self.toys) == 0: + return "{} är en {} som inte har några leksaker!".format( + self.name, self.kind + ) + else: + return "{} är en {} som har följande leksaker: {}!".format( + self.name, self.kind, ", ".join(self.toys) + ) diff --git a/laboration5/uppg_1.py b/laboration5/uppg_1.py new file mode 100644 index 0000000..75ec87e --- /dev/null +++ b/laboration5/uppg_1.py @@ -0,0 +1,18 @@ +from klasser import * + +hund1 = Pet() +hund1.name = "Pluto" +hund1.kind = "hund" + + +# hund1.add_toy("boll") +print(hund1) + +katt1 = Pet("Misse") +katt1.kind = "katt" + +katt1.add_toy("fjäder") +print(katt1) + +katt1.add_toy("höna") +print(katt1)