summaryrefslogtreecommitdiff
path: root/comp/hw/113/2.py
diff options
context:
space:
mode:
authorstandenboy <you@example.com>2024-02-28 20:07:53 +0000
committerstandenboy <you@example.com>2024-02-28 20:07:53 +0000
commit647d3b98658ddae66882badc508633c9a33eff32 (patch)
treefb8869aecac61b31b05b350d486e46aed54ef9a9 /comp/hw/113/2.py
parente4864bf1cd9e192eb54e492aaf02a397e143539c (diff)
added homework
Diffstat (limited to 'comp/hw/113/2.py')
-rw-r--r--comp/hw/113/2.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/comp/hw/113/2.py b/comp/hw/113/2.py
new file mode 100644
index 0000000..cdcc622
--- /dev/null
+++ b/comp/hw/113/2.py
@@ -0,0 +1,42 @@
+toWrite = """Sword,5
+Mace,3
+Warhammer,8
+Shield,1
+Spear,6
+"""
+
+def getLowest(list):
+ lowest = 1000
+ for i in list:
+ if i < lowest:
+ lowest = i
+ return lowest
+
+f = open("./items", "w")
+
+f.write(toWrite)
+
+f.close()
+
+f = open("./items", "r")
+
+items = []
+for i in f.readlines():
+ tmp = []
+ tmp.append(i.split(",")[0])
+ tmp.append(int(i.split(",")[1].strip("\n ")))
+ items.append(tmp)
+
+amounts = []
+for i in items:
+ amounts.append(i[1])
+sorted = []
+
+for x in range(len(items)):
+ for i in items:
+ if i[1] == getLowest(amounts):
+ sorted.append(i[0])
+ items.remove(i)
+ amounts.remove(getLowest(amounts))
+
+print(*sorted, sep=" ")