Battleship

This is a game of Battleship between the user and the CPU.

Battleship

This is a game of battleship.

Rock, Paper, and Scissors

This is a game of rock, paper, and scissors between the CPU and the user. First one to win 10 rounds wins.

Simple Register Form

This is a registration from that asks you your first and last name, you birth year, and your favorite book,sport, and movie

Guessing Game

This is a guessing game in which the user has to guess a number that the CPU is thinking of from 1 to 100 in 5 tries.

Calculator

This is a two number calculator which adds, subtracts, multiplies, and divides two numbers (whole and decimal)/

Rock, Paper, and Scissors

You play Rock, Paper, and Scissors 9 times with the CPU. After the 9 games, the CPU tells you if you beat the CPU or if you lost to it.

Battleship

You have 4 tries to sink the ship and win.

Linear Regression


x = [1, 5, 3, 4, 7, 9, 12, 13, 15, 16, 17, 4, 5, 2, 10, 23, 25] y = [5, 12, 23, 14, 17, 8, 20, 21, 25, 38, 42, 10, 13, 7, 23, 50, 55] def SlopeD(x, y, slope, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope * x[i]) + yInt difference = (y[i] - predicted) * x[i] total += difference returnValue = (-2/length) * total return returnValue def InterceptD(x, y, slope, yInt): length = len(x) total = 0 for i in range(length): predicted = (slope * x[i]) + yInt difference = (y[i] - predicted) total += difference returnValue = (-2/length) * total return returnValue m = 0 c = 0 l = 0.000001 iterations = 99999 for i in range(iterations): slope = SlopeD(x, y, m ,c) intercept = InterceptD(x, y, m ,c) m = m - (l * slope) c = c - (l * intercept) print (m, c)

K Nearest Neighbor (KNN)


import operator import math from math import sqrt data = [(1, 10, "blue"), (3, 9, "blue"), (4,8, "red"),(6, 0, "blue"), (6, 7, "red"), (5,9, "red"),(3, 2, "blue"), (4, 6, "blue"), (4,2, "red"),(3, 0, "blue"), (4, 7, "blue"), (7,4, "red"),(3, 11, "blue"), (11, 9, "blue"), (1, 14, "blue"), (2, 2, "blue"), (12,8, "red")] mydictionary = {} xcorrdinate = int(input("Enter a x-coordinate: ")) ycorrdinate = int(input("Enter a y-coordinate: ")) k = int(input("Enter value for K: ")) for y in data: distance = sqrt((xcorrdinate - y[0])**2 + (ycorrdinate - y[1])**2) mydictionary[y] = distance sorted_x = sorted(mydictionary.items(), key = operator.itemgetter(1)) list = [] colors = [] for x in sorted_x: list.append(x[1]) for y in range(k): print(sorted_x[y][1]) for z in range(k): colors.append(sorted_x[z][0][2]) def most_frequent(colors): return max(set(colors), key = colors.count) print(most_frequent(colors))
1