push
authorNils <forssennils@gmail.com>
Mon, 4 Apr 2022 16:51:57 +0000 (18:51 +0200)
committerNils <forssennils@gmail.com>
Mon, 4 Apr 2022 16:51:57 +0000 (18:51 +0200)
laboration4/uppgift_3.py
laboration5/__pycache__/klasser.cpython-39.pyc [new file with mode: 0644]
laboration5/basics.py [new file with mode: 0644]
laboration5/klasser.py [new file with mode: 0644]
laboration5/uppg_1.py [new file with mode: 0644]

index 458a41d9f31e6d2b1580c10f8be55c0b0ee51f21..59226d46ffd41849d92999c15ff62cf20a48ce20 100644 (file)
@@ -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 (file)
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 (file)
index 0000000..897b2e7
--- /dev/null
@@ -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 (file)
index 0000000..6092d10
--- /dev/null
@@ -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 (file)
index 0000000..75ec87e
--- /dev/null
@@ -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)