From 5fbd145a080da6c02a15cd4f78fab940ce046b09 Mon Sep 17 00:00:00 2001 From: standenboy Date: Wed, 10 Jan 2024 13:44:03 +0000 Subject: added 109 homework --- comp/hw/109/grid.py | 11 +++++++++++ comp/hw/109/hangman.py | 19 +++++++++++++++++++ comp/hw/109/matrix.py | 10 ++++++++++ comp/hw/109/range.py | 8 ++++++++ comp/hw/109/words.py | 8 ++++++++ 5 files changed, 56 insertions(+) create mode 100644 comp/hw/109/grid.py create mode 100644 comp/hw/109/hangman.py create mode 100644 comp/hw/109/matrix.py create mode 100644 comp/hw/109/range.py create mode 100644 comp/hw/109/words.py (limited to 'comp/hw') diff --git a/comp/hw/109/grid.py b/comp/hw/109/grid.py new file mode 100644 index 0000000..b418aeb --- /dev/null +++ b/comp/hw/109/grid.py @@ -0,0 +1,11 @@ +import sys +for i in range(1,11): + for j in range(1,11): + num = i*j + if i == j: + sys.stdout.write("* ") + elif i + j == 11: + sys.stdout.write("$ ") + else: + sys.stdout.write(f"{str(j*i)} ") + print() diff --git a/comp/hw/109/hangman.py b/comp/hw/109/hangman.py new file mode 100644 index 0000000..9749838 --- /dev/null +++ b/comp/hw/109/hangman.py @@ -0,0 +1,19 @@ +import random +words = ["hello", "there", "this", "is", "a", "line"] + +word = words[random.randint(0,len(words)-1)] + +print(len(word)) + +for i in range(5): + letter = input("guess a letter: ") + if letter in word: + print("yes") + else: + print("no") + +guess = input("guess the word: ") +if guess == word: + print("you win") +else: + print("!(you win)") diff --git a/comp/hw/109/matrix.py b/comp/hw/109/matrix.py new file mode 100644 index 0000000..3e95ff2 --- /dev/null +++ b/comp/hw/109/matrix.py @@ -0,0 +1,10 @@ +matrix = [[1,2,3],[4,5,6],[7,8,9]] + +num = int(input("number: ")) + +for i in matrix: + for j in i: + if j == num: + print("true") + exit(0) +print("false") diff --git a/comp/hw/109/range.py b/comp/hw/109/range.py new file mode 100644 index 0000000..49b3a7a --- /dev/null +++ b/comp/hw/109/range.py @@ -0,0 +1,8 @@ +import sys + +num1 = int(input("num 1: ")) +num2 = int(input("num 2: ")) + +for i in range(num1, num2+1): + sys.stdout.write(f" {str(i)}") +print() diff --git a/comp/hw/109/words.py b/comp/hw/109/words.py new file mode 100644 index 0000000..516275f --- /dev/null +++ b/comp/hw/109/words.py @@ -0,0 +1,8 @@ +import random + +words = ["hello", "there", "this", "is", "a", "line"] + +for i in range(6): + word = words[random.randint(0,len(words)-1)] + print(word) + words.remove(word) -- cgit v1.2.3