Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5d096a2
Finished Hw assignment
maxwjohn Jan 14, 2022
e1c55a4
Finish HW 00
maxwjohn Jan 14, 2022
d9bcf93
Finish HW 00
maxwjohn Jan 14, 2022
37c8775
FInish HW00
maxwjohn Jan 14, 2022
494d359
finish ex 01
maxwjohn Jan 20, 2022
a1c0585
rando
maxwjohn Jan 20, 2022
a8ebad4
Added letter function
maxwjohn Jan 20, 2022
9457d4b
wording fix
maxwjohn Jan 20, 2022
d0df785
Final edits
maxwjohn Jan 22, 2022
e319b1c
last edits
maxwjohn Jan 22, 2022
a8e0863
finish exercise 2
maxwjohn Jan 29, 2022
8ab0dea
finsh exercise 3
maxwjohn Feb 6, 2022
a5b7aea
last edits ex03
maxwjohn Feb 6, 2022
0a64211
finsihing
maxwjohn Feb 17, 2022
3feb192
done
maxwjohn Feb 17, 2022
06731a7
start ex05
maxwjohn Feb 20, 2022
899eb96
ex 05
maxwjohn Feb 20, 2022
a603e1d
ex 5 work
maxwjohn Feb 21, 2022
81b52c7
ex 05
maxwjohn Feb 22, 2022
f503896
ex05
maxwjohn Feb 22, 2022
85ede61
finish ex05
maxwjohn Feb 23, 2022
17ff2c9
finish ex05
maxwjohn Feb 23, 2022
42e5e16
ex06
maxwjohn Mar 1, 2022
70ecdee
ls 20
maxwjohn Mar 2, 2022
a2b0eb2
exercises
maxwjohn Mar 7, 2022
46f616e
d
maxwjohn Mar 7, 2022
9f956a2
d
maxwjohn Mar 8, 2022
ea4102b
Merge branch 'main' of https://github.com/comp110-22s/comp110-22s-wor…
maxwjohn Mar 8, 2022
2b666b9
ex 07
maxwjohn Mar 20, 2022
6ae128f
ex07
maxwjohn Mar 25, 2022
06babf9
Merge branch 'main' of https://github.com/comp110-22s/comp110-22s-wor…
maxwjohn Mar 25, 2022
a2b69e6
ex08
maxwjohn Mar 30, 2022
7bb3bd5
lessons
maxwjohn Mar 30, 2022
33522e7
ls 27
maxwjohn Mar 30, 2022
e032ec2
lsv27
maxwjohn Apr 4, 2022
3ca2ec6
Merge branch 'main' of https://github.com/comp110-22s/comp110-22s-wor…
maxwjohn Apr 4, 2022
83b1b9e
lesson
maxwjohn Apr 12, 2022
edb668d
ex 09
maxwjohn Apr 19, 2022
2c9bfa9
end semester lessons
maxwjohn Apr 27, 2022
808ac77
ex 10
maxwjohn Apr 28, 2022
c196ce6
ex10
maxwjohn Apr 29, 2022
87a61cd
ex
maxwjohn Apr 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
892 changes: 892 additions & 0 deletions data/titanic.csv

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions data/weather.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
date,low,high
10/16,57,75
10/17,57,76
10/18,62,75
10/19,64,79
5 changes: 5 additions & 0 deletions exercises/ex00_hello_world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""My first program for Comp110."""

__author__ = "730405989"

print("Hello, world.")
58 changes: 58 additions & 0 deletions exercises/ex01_chardle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""EX01 - Chardle - A cute step toward Wordle."""

__author__ = "730405989"

key_word: str = str(input("Enter a 5-character word: "))

if len(key_word) != 5:
print("Error: Word must contain 5 characters")
exit()

if not key_word.isalpha():
print("Error: Word must be made of 5 letters")
exit()
key_letter: str = str(input("Enter a single character: "))

searching_statement: str = "Searching for " + key_letter + " in " + key_word
if not key_letter.isalpha():
print("Error: Character must be a letter")
exit()

if len(key_letter) != 1:
print("Eror: Character must be a single character")
exit()
else:
print(searching_statement)
if ord(key_letter) == ord(key_word[0]):
index_zero = 1
print(key_letter + " found at index 0")
else:
index_zero = int(0)
if ord(key_letter) == ord(key_word[1]):
index_one = int(1)
print(key_letter + " found at index 1")
else:
index_one = int(0)
if ord(key_letter) == ord(key_word[2]):
index_two = int(1)
print(key_letter + " found at index 2")
else:
index_two = int(0)
if ord(key_letter) == ord(key_word[3]):
index_three = int(1)
print(key_letter + " found at index 3")
else:
index_three = int(0)
if ord(key_letter) == ord(key_word[4]):
index_four = int(1)
print(key_letter + " found at index 4")
else:
index_four = int(0)
number_instances: int = int(index_one + index_two + index_three + index_zero + index_four)
if number_instances == 0:
print("No instances of " + key_letter + " found in " + key_word)
else:
if number_instances == 1:
print("1 instance of " + key_letter + " found in " + key_word)
else:
print(str(number_instances) + " instances of " + key_letter + " found in " + key_word)
52 changes: 52 additions & 0 deletions exercises/ex02_one_shot_wordle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""One shot Wordle, a big step towards Wordle."""

__author__ = "730405989"

secret_word = "python"

guess: str = str(input(f"What is your {len(secret_word)} letter guess? "))
# Set up input string for guess to insure it is proper length and only made up of letters.############

while ((len(guess) != len(secret_word)) or not guess.isalpha()):
guess = (input(f"That was not {len(secret_word)} letters! Try again: "))

counter = int(0)

white_box: str = "\U00002B1C"
green_box: str = "\U0001F7E9"
yellow_box: str = "\U0001F7E8"

box_response: str = ""
while counter < len(secret_word):
secret_word_test = secret_word[counter]
guess_test = guess[counter]

# Setting up while loop that tests whether each letter is contained in the secret word############
# Also should mention adding strings of the box together through a relative reassingment operator.##########
if ord(secret_word_test) == ord(guess_test):
box_response = str(box_response + green_box)
counter += 1
else:
i = 0
yellow_test = False
while i < len(secret_word) and not yellow_test:
if ord(guess_test) == ord(secret_word[i]):
yellow_test = True
i = 7
else:
i += 1
if yellow_test:
box_response = str(box_response + yellow_box)
else:
box_response = str(box_response + white_box)
counter += 1
print(box_response)

# Second while statement is if letter is not in the right index, while loop tests it at other indices to check whether that letter is######
# there, and if it is the variable yellow_letter is set to True, and I set it arbitrarily to 7 to get it to exit the loop######
# Then I tested whether yellow_test was true, and if it was printed a yellow box and if it was not printed the white box#######
if guess == secret_word:
print("Woo! You got it!")
else:
print("Not quite. Play again soon! ")
# Easy part, if guess was the secret word, printed congratulatory statement versus if it was not, printed retry statement########
82 changes: 82 additions & 0 deletions exercises/ex03_wordle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""Wordle -- This time using functions."""

__author__ = "730405989"


def contains_char(test_word: str, test_letter: str) -> bool:
"""Tests whether letter is contained in the word."""
assert len(test_letter) == 1
counter = 0
while counter < len(test_word):
if ord(test_word[counter]) == ord(test_letter):
counter = len(test_word)
return True
# Tests if letter is contained, going letter by letter, and returning true when/if a letter is found########
else:
counter += 1
return False


def emojified(guess: str, secret: str) -> str:
"""Given guess and key word returns emoji string that represents correctness of the guess."""
assert len(guess) == len(secret)
emoji_string: str = str("")
white_box: str = "\U00002B1C"
green_box: str = "\U0001F7E9"
yellow_box: str = "\U0001F7E8"
# Setting up string for boxes and empty emoji string that will be added to#################
i = 0
while i < len(secret):

secret_test: str = secret[i]
guess_test: str = guess[i]
# Setting up tests to test via counter and while loop letter by letter#############
if ord(secret_test) == ord(guess_test):
emoji_string += green_box
i += 1
else:
if contains_char(secret, guess_test):
emoji_string += yellow_box
i += 1
else:
emoji_string += white_box
i += 1
# If letter is right(guess = secret), green box given, if not, use contains character function to test######
return emoji_string


def input_guess(int_length: int) -> str:
"""Prompts user for input word."""
input_word: str = str(input(f"Enter a {int_length} character word: "))
while len(input_word) != int_length:
input_word = str(input(f"That wasn't {int_length} chars! Try again: "))
# Unsure if grader reads this part, but if you can add comments, add comment on how to store variable above without getting Safety Type Error####
# Prompting input guess, and if guess not of proper length, reissue a prompt to reguess untill correct length########
return input_word


def main() -> None:
"""The entrypoint of the program and main game loop."""
n = 1
lose = True
# lose is variable used to indicate if the guess is incorrect######
key_word: str = str("naomi")
while n <= 6 and lose:
print(f'=== Turn {n}/6 ===')
guess_n: str = str(input_guess(len(key_word)))
# guessn variable to store the input guess at the current guess######
print(emojified(guess_n, key_word))
if guess_n == key_word:
lose = False
else:
n += 1

if not lose:
print(f"You won in {n}/6 turns!")
else:
print("X/6 - Sorry, try again tomorrow!")
return


if __name__ == "__main__":
main()
187 changes: 187 additions & 0 deletions exercises/ex04_turtle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
"""A feeble attempt at drawing a basketball court."""

__author__ = "730405989"

from turtle import Turtle, colormode, done

colormode(255)


def main() -> None:
"""The entrypoint of my scene."""
pen: Turtle = Turtle()
# Pen is turtle variable because it is like a pen
pen.color('gray')
pen.left(90)
draw_post(pen, 0, -250, 300)

# regulation size basketball backboard is 182.9 X 126.9
pen.begin_fill()
draw_rect(pen, 91.45, 50, 182.9, 126.9)

pen.color('black')
pen.left(90)
draw_rect(pen, -25, 100, 50, 40)

# Basketball rim
pen.color('orange')
pen.right(90)
draw_curve(pen, 25, 60, 75, 180)

# Basketballs
pen.right(90)
pen.begin_fill()
draw_curve(pen, -100, 0, 80, 360)
pen.end_fill()

# Basketball scoreboard
draw_scoreboard(pen)

done()


def goto_skip(pen: Turtle, x: float, y: float) -> None:
"""Function to run penup and move then pendown."""
pen.penup()
pen.goto(x, y)
pen.pendown()


# A little unneccesary, but only purpose to draw post, could draw other lines
def draw_post(pen: Turtle, x: float, y: float, height: float) -> None:
"""Function to draw post, also could be used to draw any other straight line."""
goto_skip(pen, x, y)
pen.forward(height)


def draw_rect(pen: Turtle, x: float, y: float, width: float, length: float) -> None:
"""Function to draw rectangles of different widths and lenghts."""
goto_skip(pen, x, y)
i: int = 0
# while loop to draw rectangle
while (i < 5):

if i < 1:
pen.left(90)
pen.forward(width)
else:
pen.right(90)
if i == 2:
pen.forward(width)
else:
pen.forward(length)
i = i + 1
pen.end_fill()


def draw_curve(pen: Turtle, x: float, y: float, diameter: float, rotation: float) -> None:
"""Function that draws a curve by inching forward and rotating degree by degree."""
goto_skip(pen, x, y)
i = 0
step: float = float(diameter / rotation)
while i < rotation:
pen.forward(step)
pen.right(1)
i += 1


def draw_t(pen: Turtle, x: float, y: float, size: int) -> None:
"""Function that draws a T."""
goto_skip(pen, x, y)
pen.forward(size)
pen.penup()
pen.right(90)
# Like this, a lot of the values are estimated, such as size/ 3 and were then trail and errored to see if they fit okay
pen.forward(size / 3)
pen.left(180)
pen.pendown()
pen.forward(size * 2 / 3)
# 2/3 another estimate about letter t


def draw_e(pen: Turtle, x: float, y: float, size: int) -> None:
"""Function that draws an E."""
goto_skip(pen, x + 5, y)
pen.right(90)
pen.forward(size)
pen.right(90)
pen.forward(size / 3)
goto_skip(pen, x + 5, y + (size / 2))
pen.forward(size / 3)
goto_skip(pen, x + 5, y)
pen.forward(size / 3)
# More trial and error trying to make letters not look horrible


def draw_a(pen: Turtle, x: float, y: float, size: int) -> None:
"""Function that draws A."""
goto_skip(pen, x, y)
pen.right(30)
pen.forward(size)
pen.right(135)
pen.forward(size)
goto_skip(pen, x + size / 4, y + size / 3)
pen.left(75)
pen.forward(size * 2 / 3)
# This letter worst of all pretty estimated


def draw_m(pen: Turtle, x: float, y: float, size: int) -> None:
"""Function that draws M."""
goto_skip(pen, x, y)
pen.left(90)
pen.forward(size)
pen.right(135)
pen.forward(size / 2)
pen.left(90)
pen.forward(size / 2)
pen.right(135)
pen.forward(size)
# Pretty straightforward, just going forward, right, left etc...


def draw_1(pen: Turtle, x: float, y: float, size: int) -> None:
"""Function draws 1."""
goto_skip(pen, x, y)
pen.forward(size)
pen.left(150)
pen.forward(size / 2)


def draw_team(pen: Turtle, x: float, y: float) -> None:
"""Function that puts letter functions together to spell team."""
draw_t(pen, x, y, 15)
draw_e(pen, x + 8, y, 15)
pen.left(90)
draw_a(pen, x + 20, y, 15)
draw_m(pen, x + 35, y, 15)
# The adding gives space between letters


def draw_scoreboard(pen: Turtle) -> None:
"""Draw scoreboard, putting bunch of functions together."""
pen.color(55, 118, 171)
# Fill in scoreboard light blue
pen.right(90)
pen.penup()
pen.goto(-300, 250)
pen.begin_fill()
draw_rect(pen, -300, 250, 200, 150)
pen.end_fill()
pen.left(90)
pen.color('black')
draw_team(pen, -280, 230)
pen.right(180)
draw_team(pen, -180, 230)
# Draw team 2 times on different sides of scoreboard
draw_rect(pen, -270, 220, 30, 30)
pen.right(90)
draw_rect(pen, -170, 220, 30, 30)
pen.left(90)
draw_1(pen, -255, 195, 15)
pen.right(150)
draw_1(pen, -155, 195, 15)
# draws score section in scoreboard


main()
Loading