#Dougherty Valley High School


DNA Reader with inputs

This program uses a DNA strand inputted in a text box to convert it to amino acids.

Battleship on a Website

This is a game of battleship run on a website. The preview is a bit wonky.

Game of Rock, Paper, Scissors on a Website

A game of rock, paper, scissors run on a website.

Basic Registeration Prompt

This is a form that asks a series of questions and then records it right below the text box. It isn't fully styled yet, but the functionality is more or less complete.

Guessing Game run on Website

This is a guessing game that is run on a website. The backend was coded in javascript. The submit button checks to see if the number entered in the textBox matches the correct number, the hint button tells you if the number was lower or higher than the last number that you guessed, and the start over button lets you start over whenever you click it. All buttons are disabled upon running out of guesses.

Website Calculator

This is a calculator that is run on a website. Currently, it is only a two number calculator that accepts both decimal and whole numbers.

Game of Battleship in JavaScript

This game of battleship has a 1x1 battleship randomly generated in a 5x5 board. The player has 4 guesses to guess the exact location of the ship. Each miss is marked with a "X" and a "V" is put in place of the battleship's location if you guess it correctly. The coordinates of the ship are given after you run out of guesses.


console.log("Let's play battleship! Try to guess correctly in 4 guesses"); var board = [ ["O", "O", "O", "O", "O"], ["O", "O", "O", "O", "O"], ["O", "O", "O", "O", "O"], ["O", "O", "O", "O", "O"], ["O", "O", "O", "O", "O"] ] console.log(board); function battleship(board, turns){ var compx = Math.floor(Math.random() * 5); var compy = Math.floor(Math.random() * 5); var playerx = prompt("Guess row: "); var playery = prompt("Guess column: "); var i = 1; while (i < (turns)) { if ((compx != playerx && compy != playery) || (compx != playerx && compy == playery) || (compx == playerx && compy != playery)){ board[playerx][playery]= "X"; console.log("You missed my battleship! Turn "+i+" of "+turns); console.log(board); playerx = prompt("Guess row: "); playery = prompt("Guess column: "); } else if (compx == playerx && compy == playery){ board[playerx][playery]= "V"; console.log("You sunk my battleship!"); console.log(board); break; } i+=1; } console.log("The coordinates were "+compx+","+compy); } battleship(board, 4);

Game of Rock, Paper, Scissors in JavaScript

This game of Rock, Paper, Scissors is played between the computer and the user. The choice is given in all lowercase and standard rules for the game apply. After 10 rounds, the scores are tallied and the player with the higher round wins is the winner and the number of wins is displayed at the end.


var choices = ["rock", "paper", "scissors"]; function rps(timesPlayed){ var choices = ["rock", "paper", "scissors"]; var messsage; var final; var playerWins = 0; var compWins = 0; for (var i=0;i<timesPlayed;i++){ var playerChoice = prompt("rock, paper, or scissors? "); var compChoice = choices[Math.floor(Math.random() * choices.length)]; if (playerChoice == "rock" && compChoice == "scissors") { message = "The rock broke the scissors. Player wins!"; playerWins++; } else if (playerChoice == "paper" && compChoice == "rock") { message = "The paper covers the rock. Player wins!"; playerWins++; } else if (playerChoice == "scissors" && compChoice == "paper") { message = "The scissors cut the paper. Player wins!"; playerWins++; } else if (playerChoice == "scissors" && compChoice == "rock") { message = "The rock broke the scissors. Computer wins!"; compWins++; } else if (playerChoice == "paper" && compChoice == "scissors") { message = "The scissors cut the paper. Computer wins!"; compWins++; } else if (playerChoice == "rock" && compChoice == "paper") { message = "The paper covers the rock. Computer wins!"; compWins++; } else if (playerChoice == compChoice) { message = "Draw!"; } console.log(message); } playerWins > compWins ? final = "Player wins! Wins: "+playerWins+"/10" : final = "Computer wins! Wins: "+compWins+"/10"; console.log(final); } rps(10);

Hierarchical Clustering

An initial attempt at the hierarchical clustering algorithm from machine learning. Given a set of data and a value for the number of clusters (k), the algorithm goes through the data and clusters elements that are closest together. It first treats every point as a cluster, then clusters the closest clusters, and repeats until the desired amount of clusters are made. The linked video better describes the algorithm. The output of this algorithm is reflective of how the clustering would appear on dendrogram - each pair corresponds to the values clustered and in what order. I say that this is an initial attempt because I can already see some flaws in the code and factors that I have not considered. The code can also be greatly improved in general - for starters, it should consider data in different dimensions (though that shouldn't be too difficult to implement).



data=[23,9,14,44,42,29,18,33,2,61] cdata=data.copy() def average(mylist): sum=0 for i in mylist: sum=sum+i return sum/len(mylist) dlist=[] ddict={} con=True while con==True: k=int(input("How many clusters do you wish to form")) if k<len(data): con=False else: print("Invalid value for k, please select another") for i in range(k): for i in cdata: for j in cdata: d=abs(i-j) if d!=0 and dlist.count(d)==0: dlist.append(d) ddict[d]=[i,j] dlist.sort() a=ddict[dlist[0]] for i in a: cdata.remove(i) cdata.append(average(ddict[dlist[0]])) ddict.clear() dlist.clear() print(a)

KNN(K Nearest Neighbors)

This is my final version of K Nearest Neighbors. I still may need to add more points.


from statistics import mode from math import sqrt import operator data = [(1,1,"red"),(2,4,"red"),(6,3,"red"),(7,4,"blue"),(4,2,"blue"),(3,4,"green")] x = int(input("What is the x value?")) y = int(input("What is the y value?")) k = int(input("How many closest points would you like?")) point = (x,y) print(point) def distance(x2,y2): dist = ((x2[0]-x)**2)+((y2[1]-y)**2) return sqrt(dist) if k>len(data): print("Enter a different number of points") Dictionary = {} for i in range(0,len(data)): var = distance(data[i],data[i]) print(var) Dictionary[data[i]]=var sorted_Dictionary = sorted(Dictionary.items(), key=operator.itemgetter(1)) print(sorted_Dictionary) Dict = {} start = 0 var2 = [] for i in range(0,k): var1 = (sorted_Dictionary[i][0][2]) Dict[start] = var1 start = start + 1 for i in range(0,k): var2.append(Dict[i]) print(var2) def most_frequent(var2): return max(set(var2), key = var2.count) print("Your color is:") print(most_frequent(var2))

KNN(K Nearest Neighbors)

This is my final version of K Nearest Neighbors. I still may need to add more points.


from statistics import mode from math import sqrt import operator data = [(1,1,"red"),(2,4,"red"),(6,3,"red"),(7,4,"blue"),(4,2,"blue"),(3,4,"green")] x = int(input("What is the x value?")) y = int(input("What is the y value?")) k = int(input("How many closest points would you like?")) point = (x,y) print(point) def distance(x2,y2): dist = ((x2[0]-x)**2)+((y2[1]-y)**2) return sqrt(dist) if k>len(data): print("Enter a different number of points") Dictionary = {} for i in range(0,len(data)): var = distance(data[i],data[i]) print(var) Dictionary[data[i]]=var sorted_Dictionary = sorted(Dictionary.items(), key=operator.itemgetter(1)) print(sorted_Dictionary) Dict = {} start = 0 var2 = [] for i in range(0,k): var1 = (sorted_Dictionary[i][0][2]) Dict[start] = var1 start = start + 1 for i in range(0,k): var2.append(Dict[i]) print(var2) def most_frequent(var2): return max(set(var2), key = var2.count) print("Your color is:") print(most_frequent(var2))

KNN(K Nearest Neighbors)

This is my version of K nearest neighbors in python. What this code is doing is it is taking in a point entered by the user. Then is finds what color that point belongs in. So far my code is only able to categorize the point when asked for only one nearest point, I will have to work on this in the future. I will also have to add more points to the data set.


from statistics import mode from math import sqrt import operator data = [(1,1,"red"),(2,4,"red"),(6,3,"red"),(7,4,"blue"),(4,2,"blue"),(3,4,"green")] x = int(input("What is the x value?")) y = int(input("What is the y value?")) k = int(input("How many closest points would you like?")) point = (x,y) print(point) def distance(x2,y2): dist = ((x2[0]-x)**2)+((y2[1]-y)**2) return sqrt(dist) if k>len(data): print("Enter a different number of points") Dictionary = {} for i in range(0,len(data)): var = distance(data[i],data[i]) print(var) Dictionary[data[i]]=var sorted_Dictionary = sorted(Dictionary.items(), key=operator.itemgetter(1)) print(sorted_Dictionary) for i in range(0,k): var1 = (sorted_Dictionary[0][0][2]) print(var1)
1 2 3