From eb1a5582181bf3188f30d665a295321d36bdc795 Mon Sep 17 00:00:00 2001 From: standenboy Date: Thu, 25 Jan 2024 10:57:10 +0000 Subject: did the cover work --- comp/work/21/minesweeper.py | 66 +++++++++++++++++++++++++++++++++++++++++++++ comp/work/21/money.py | 3 +++ comp/work/21/mysum.py | 14 ++++++++++ comp/work/21/names.py | 15 +++++++++++ comp/work/21/results.py | 22 +++++++++++++++ comp/work/21/timestables.py | 10 +++++++ 6 files changed, 130 insertions(+) create mode 100644 comp/work/21/minesweeper.py create mode 100644 comp/work/21/money.py create mode 100644 comp/work/21/mysum.py create mode 100644 comp/work/21/names.py create mode 100644 comp/work/21/results.py create mode 100644 comp/work/21/timestables.py (limited to 'comp/work/21') diff --git a/comp/work/21/minesweeper.py b/comp/work/21/minesweeper.py new file mode 100644 index 0000000..2a6be22 --- /dev/null +++ b/comp/work/21/minesweeper.py @@ -0,0 +1,66 @@ +import random +grid = [ + [0,0,0,0,0,0], + [0,0,0,0,0,0], + [0,0,0,0,0,0], + [0,0,0,0,0,0], + [0,0,0,0,0,0], + [0,0,0,0,0,0], + ] + +def getValidPos(text): + inp = -1 + while inp < 1 or inp > 6: + inp = int(input(text)) + return inp + +def printGrid(): + for i in grid: + for j in i: + if j == "B": + print("0", end = " ") + else: + print(j, end = " ") + print() + +def placeBombs(amount): + for i in range(amount): + grid[random.randint(0,5)][random.randint(0,5)] = "B" + +def isMineNear(row, collumn): + row = row - 1 + collumn = collumn - 1 + try: + if grid[row][collumn+1] == "B": + print("a bomb is near") + elif grid[row][collumn-1] == "B": + print("a bomb is near") + elif grid[row+1][collumn] == "B": + print("a bomb is near") + elif grid[row-1][collumn] == "B": + print("a bomb is near") + elif grid[row+1][collumn+1] == "B": + print("a bomb is near") + elif grid[row-1][collumn-1] == "B": + print("a bomb is near") + elif grid[row-1][collumn+1] == "B": + print("a bomb is near") + elif grid[row+1][collumn-1] == "B": + print("a bomb is near") + except: + pass + + +placeBombs(10) + +score = 0 +while True: + printGrid() + row = getValidPos("row: ") + collumn = getValidPos("collumn: ") + if grid[row-1][collumn-1] == "B": + print("you blew up, your score was", score) + break + grid[row-1][collumn-1] = "G" + score = score + 1 + isMineNear(row, collumn) diff --git a/comp/work/21/money.py b/comp/work/21/money.py new file mode 100644 index 0000000..55e7ecd --- /dev/null +++ b/comp/work/21/money.py @@ -0,0 +1,3 @@ +money = float(input("amount of money: ")) + +print(f"${money:.2f}") diff --git a/comp/work/21/mysum.py b/comp/work/21/mysum.py new file mode 100644 index 0000000..fdbb0bb --- /dev/null +++ b/comp/work/21/mysum.py @@ -0,0 +1,14 @@ +nums = [[3,7,12,5],[8,4,1,6],[15,0,2,6]] + +def mysum(list): + total = 0 + for i in list: + total = total + i + return total + + +total = 0 +for i in nums: + total = total + mysum(i) + +print(total) diff --git a/comp/work/21/names.py b/comp/work/21/names.py new file mode 100644 index 0000000..9c322b9 --- /dev/null +++ b/comp/work/21/names.py @@ -0,0 +1,15 @@ +names = [] +for i in range(5): + name = input("name: ") + names.append(name) + +f = open("names.txt", "r+") +for i in names: + i = i+"\n" + f.write(i) + +nameToSearch = input("name to search: ") +for i in f.readlines(): + if i.split("\n")[0] == nameToSearch: + print("name found") + break diff --git a/comp/work/21/results.py b/comp/work/21/results.py new file mode 100644 index 0000000..bfd2d2f --- /dev/null +++ b/comp/work/21/results.py @@ -0,0 +1,22 @@ +results = [] + +more = "yes" + +while more.lower() == "yes": + result = 0 + tmp = [] + while True: + result = int(input("result: ")) + if result == -1: + break + if result < 0: + print("invalid input") + elif result > 100: + print("invalid input") + else: + tmp.append(result) + results.append(tmp) + more = input("add results for another student? ") + +for i in range(len(results)): + print("student",i+1,"got: ", *results[i]) diff --git a/comp/work/21/timestables.py b/comp/work/21/timestables.py new file mode 100644 index 0000000..0e4c07e --- /dev/null +++ b/comp/work/21/timestables.py @@ -0,0 +1,10 @@ +for i in range(1,12): + for j in range(1,12): + num = i * j + if num < 10: + print(f"00{num} ", end="") + elif num < 100: + print(f"0{num} ", end="") + else: + print(f"{num} ", end="") + print() -- cgit v1.2.3