Skip to content
Open

need #10

Show file tree
Hide file tree
Changes from all commits
Commits
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
801 changes: 801 additions & 0 deletions data/pokemon.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,56,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 COMP 110."""

__author__ = "730465187"

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

__author__ = "730465187"

selected_word: str = str(input("Enter a 5-character word: "))
selected_word_length = len(selected_word)


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


character: str = str(input("Enter a single character: "))
character_length = len(character)

if character_length == 1:
print("Searching for", character, "in", selected_word)
else:
print("Error: Character must be a single character")
exit()

character_instances = 0

if selected_word[0] == character:
print(character, "found at index 0")
character_instances = character_instances + 1

if selected_word[1] == character:
print(character, "found at index 1")
character_instances = character_instances + 1

if selected_word[2] == character:
print(character, "found at index 2")
character_instances = character_instances + 1

if selected_word[3] == character:
print(character, "found at index 3")
character_instances = character_instances + 1

if selected_word[4] == character:
print(character, "found at index 4")
character_instances = character_instances + 1

if character_instances == 0:
print("No instances of", character, "found in", selected_word)
else:
if character_instances == 1:
print(character_instances, "instance of", character, "found in", selected_word)
else:
print(character_instances, "instances of", character, "found in", selected_word)
45 changes: 45 additions & 0 deletions exercises/ex02_one_shot_wordle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""One shot wordle."""

__author__ = "730465187"

secret_word = str("light")

guess = str(input(f"What is your {len(secret_word)}-letter guess? "))

while len(guess) != len(secret_word):
guess = str(input(f"That was not {len(secret_word)} letters! Try again: "))
# The user inputs their guess and it is stored as the variable guess.

WHITE_BOX: str = "\U00002B1C"
GREEN_BOX: str = "\U0001F7E9"
YELLOW_BOX: str = "\U0001F7E8"

index_of_secret_word = 0
color_of_guess = str()

while index_of_secret_word < len(secret_word):
if guess[index_of_secret_word] == secret_word[index_of_secret_word]:
color_of_guess = (color_of_guess + GREEN_BOX)
# This segment of code is used to determine if the letter of the guess is equal to the letter of the secret word in the same place. If so, a green box is added to that place in the word in the output.
else:
in_word = bool(False)
i = 0
while in_word is not True and i < len(secret_word):
if secret_word[i] == guess[index_of_secret_word]:
in_word = True
else:
i = i + 1
# This loop determines whether a character in the guessed word equals a character in a different location in the secret word.
if in_word is True:
color_of_guess = (color_of_guess + YELLOW_BOX)
else:
color_of_guess = (color_of_guess + WHITE_BOX)
# This if-else statement determines whether to add a yellow box or a white box for output at a given position based on the results of the previous while loop.
index_of_secret_word = index_of_secret_word + 1
# This line moves the program from one character to the next.
print(color_of_guess)

if guess == secret_word:
print("Woo! You got it!")
else:
print("Not quite. Play again soon!")
72 changes: 72 additions & 0 deletions exercises/ex03_wordle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""The Real Wordle."""

__author__ = "730465187"


def contains_char(word: str, chr: str) -> bool:
"""Checks if a character is in the word."""
assert len(chr) == 1
i = 0
in_word = bool(False)
while i < int(len(word)) and in_word is False:
if word[i] == chr:
in_word = True
else:
i += 1
if in_word is True:
return True
else:
return False


WHITE_BOX: str = "\U00002B1C"
GREEN_BOX: str = "\U0001F7E9"
YELLOW_BOX: str = "\U0001F7E8"


def emojified(guess: str, secret: str) -> str:
"""Checks which letters are green, which are yellow, and which are white, and returns them in proper order."""
assert len(guess) == len(secret)
emojified_guess = str()
i = 0
while i < len(secret):
if guess[i] == secret[i]:
emojified_guess = (emojified_guess + GREEN_BOX)
elif contains_char(word=secret, chr=guess[i]) is True:
emojified_guess = (emojified_guess + YELLOW_BOX)
else:
emojified_guess = (emojified_guess + WHITE_BOX)
i = i + 1
return emojified_guess


def input_guess(expected_length: int) -> str:
"""Makes sure the guess is the same length as the secret word."""
guess_length = str(input(f"Enter a {expected_length} character word: "))
while len(guess_length) != expected_length:
guess_length = str(input(f"That wasn't {expected_length} chars! Try again: "))
return guess_length


def main() -> None:
"""The entrypoint of the program and the main game loop."""
i: int = 1
secret = str("candy")
won = bool(False)
while i <= 6 and won is False:
print(f"=== Turn {i}/6 ===")
guess: str = (input_guess(expected_length=len(secret)))
result: str = emojified(guess=guess, secret=secret)
print(result)
if guess == secret:
won = True
else:
i += 1
if won is True:
print(f"You won in {i}/6 turns!")
else:
print("X/6 - Sorry, try again tomorrow!")


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

__author__ = "730465187"

from random import randint

from turtle import Turtle, colormode, done
colormode(255)


def draw_background() -> None:
"""Creates the background for the scene. Breaks down the complex function of drawing the background into neater code."""
background: Turtle = Turtle()
background.speed(0)
background.penup()
background.goto(-500, -500)
background.pendown()
background.begin_fill()
background.color(6, 21, 110)
i: int = 0
while (i < 4):
background.forward(1000)
background.left(90)
i += 1
background.end_fill()


def draw_field() -> None:
"""Draws the field the players are on. Breaks down the complex function of drawing the background into neater code."""
field: Turtle = Turtle()
field.speed(0)
field.penup()
field.goto(-400, -250)
field.pendown
field.begin_fill()
field.color("brown", "green")
i = 0
while i < 2:
field.forward(1000)
field.right(90)
field.forward(100)
field.right(90)
i += 1

field.end_fill()


def draw_moon(a_turtle: Turtle, x: float, y: float, size: float) -> None:
"""Function 1/4. Draws the background and field with a moon. Implements the functions draw_background and draw_field, which makes the code neater and easier to understand."""
"""Uses the randint function to decide which type of moon to draw - full moon, crescent moon, or no moon."""
draw_background()
draw_field()
a_turtle.speed(0)
a_turtle.pu()
a_turtle.goto(x, y)
a_turtle.pd()
a_turtle.speed(100)
a_turtle.color("black", "white")
a_turtle.begin_fill()
which_moon: int = randint(1, 3)
i: int = 0
if which_moon == 1:
while (i < 60):
a_turtle.forward(size * 3)
a_turtle.left(3)
i += 1
a_turtle.setheading(-45)
counter: int = 0
while (counter < 33):
a_turtle.forward(size * 4)
a_turtle.left(-3)
counter += 1
elif which_moon == 2:
while (i < 120):
a_turtle.forward(size * 3)
a_turtle.left(3)
i += 1
a_turtle.end_fill()
a_turtle.hideturtle()


def draw_frisbee(a_turtle: Turtle, x: float, y: float) -> None:
"""Function 2/4. Draws a frisbee of a random size 1-5."""
size: int = randint(1, 5)
a_turtle.speed(0)
a_turtle.penup()
a_turtle.goto(x, y)
a_turtle.pendown()
a_turtle.begin_fill()
a_turtle.color("white", "white")
i: int = 0
while (i < 90):
a_turtle.forward(size * .25)
a_turtle.left(2)
i += 1
a_turtle.forward(size * 30)
i = 0
while (i < 90):
a_turtle.forward(size * .25)
a_turtle.left(2)
i += 1
a_turtle.forward(size * 30)
a_turtle.end_fill()
a_turtle.hideturtle()


def draw_lights(a_turtle: Turtle, x: float, y: float, size: float) -> None:
"""Function 3/4. Draws the lights."""
a_turtle.speed(0)
a_turtle.penup()
a_turtle.goto(x, y)
a_turtle.pendown
a_turtle.begin_fill()
a_turtle.color("gray")
a_turtle.left(270)
a_turtle.forward(size * 200)
a_turtle.left(90)
a_turtle.forward(20 * size)
a_turtle.left(90)
a_turtle.forward(200 * size)
a_turtle.right(90)
a_turtle.end_fill()

a_turtle.pendown()
a_turtle.begin_fill()
a_turtle.color("white", "gray")
a_turtle.pensize(5)
i = 0
while i < 60:
a_turtle.forward(size * .5)
a_turtle.left(3)
i += 1
a_turtle.forward(size * 25)
i = 0
while i < 60:
a_turtle.forward(size * .5)
a_turtle.left(3)
i += 1
a_turtle.forward(25 * size)
a_turtle.end_fill()
a_turtle.hideturtle()


def draw_player(a_turtle: Turtle, x: float, y: float, size: float) -> None:
"""Function 4/4. Draws a player."""
a_turtle.speed(0)
a_turtle.penup()
a_turtle.goto(x, y)
a_turtle.pendown()
a_turtle.color(241, 156, 107)
a_turtle.pensize(10)
a_turtle.left(45)
a_turtle.forward(size * 20)
a_turtle.right(90)
a_turtle.forward(size * 20)
a_turtle.right(180)
a_turtle.forward(size * 20)
a_turtle.right(45)
a_turtle.forward(size * 30)
a_turtle.right(90)
a_turtle.forward(size * 10)
a_turtle.right(180)
a_turtle.forward(size * 20)
a_turtle.right(180)
a_turtle.forward(size * 10)
a_turtle.left(90)
a_turtle.forward(size * 10)
a_turtle.right(90)
a_turtle.begin_fill()
i = 0
while (i < 120):
a_turtle.forward(size * .25)
a_turtle.left(3)
i += 1
a_turtle.end_fill()
a_turtle.hideturtle()


def main() -> None:
"""The entrypoint of my scene."""
moon: Turtle = Turtle()
frisbee: Turtle = Turtle()
lights: Turtle = Turtle()
player: Turtle = Turtle()
draw_moon(moon, 200, 200, 1)
draw_frisbee(frisbee, 100, -200)
draw_lights(lights, -300, -50, 1)
draw_lights(lights, 250, -50, 1)
draw_player(player, -250, -250, 1)
draw_player(player, 200, -250, 1)

done()


if __name__ == "__main__":
main()
Loading