Nexclap

gplustf2.com

Here's a website I developed on-and-off starting in middle school, and continuing to the present day. The website is for a Team Fortress 2 fan community that I was an admin for on the somewhat obscure, now-defunct social network Google+ (the group has since moved to a different social network). It uses PHP on the backend, so that most of the pages on the site use the same template. Although most of the pages aren't interactive, some parts of the site were automated, too, such as the member counter. If you click on the "30,630 members" label it takes you to a graph of how the community grew and shrunk over the course of 4 years, data collected on a daily basis by a script I wrote (pic #2). (The site was planned to have a publicly viewable archive of all the old posts in the community following Google+'s shutdown. While all the data is still there, and it was viewable at one point, this feature doesn't seem to be working at the moment)

/* The website uses many different source files because it runs on the CodeIgniter framework for PHP. Because of this, its code can't be posted in this space. I don't plan on releasing the source on GitHub but you can explore the live site at https://gplustf2.com. All the code was written by me except for the page under /artfortress18, which was done by another community admin. */

Number Guessing Game

Asks a user to guess a number and gives hints to the user based on how close the users guess is. Displays Users statistics about their games.


from random import randint condition = "yes" numgames = 0 numcount =[] while condition == "yes": num = randint(1,100) count = 0 answer = 0 while answer != num: answer = int(input(" guess a number from 1 to 100?")) count+=1 if answer < num: print( " guess a little higher") elif answer == num: print ("you guessed it") numgames+=1 numcount.append(count) else: print ("guess a little lower") condition = input(" Would you like to play again ?") print(" Here are your results") print("total games:" + str(len(numcount))) avg = 0 for i in numcount: avg+=i avg/=len(numcount) print( "Here is your average:" + str(avg)) least = numcount[0] for i in numcount: if i < least: least = i print("here was your best game:" + str(least))
Akshay Jun 05

This is amazing!

My K Nearest Neighbor Algorithm...without using SKLearn...

I created a KNN Algorithm by making my own data set with tuples storing the x-value, y-value, and color of 9 points, asking the user for the x and y-values of their data point and how many dots are being taken into account, then determining the distance between the point and the ones in the data set. I stored these distances in a dictionary, with the points being the keys and the distances being the values, and sorted it from the lowest distance to the highest. After, I totaled up the number of points with each color out of the inputted number of nearest points. Finally, I classified the inputted point based on which of the colors was the most prominent out of those points.


#Importing import numpy as np import math as math import operator #Data data = [(1, 2, "red"), (10, 8, "blue"), (5, 6, "green"), (4, 1, "red"), (8, 8, "blue"), (3, 1, "green"), (1, 2, "red"), (8, 10, "blue"), (6, 5, "green")] #Store Points(X/Y Values) x = int(input("What's your x-value?")) y = int(input("What's your y-value?")) #Store # of points being taken into account(K Value) k= int(input("How many closest dots do you want to take into account?")) point = (x, y) print(point) #Distance Formula def distance(x2, y2): return math.sqrt((x2-x)**2+(y2-y)**2) #Find/Store Distances of All Points(Loop/Dictionary) knndict = {} for n in data: z = distance(n[0],n[1]) print(z) knndict[n] = z #Ordering The Dictionary(Least Distance) knndicts = sorted(knndict.items(), key=operator.itemgetter(1)) print(knndicts) #Voting Process green = 0 blue = 0 red = 0 for n in range(0, k, 1): if knndicts[n][0][2] == "green": green += 1 if knndicts[n][0][2] == "blue": blue += 1 if knndicts[n][0][2] == "red": red += 1 print(green) print(blue) print(red) #Determining the Color if green > blue and green > red: print("Your dot's color has been classified as green!") elif blue > green and blue > red: print("Your dot's color has been classified as blue!") elif red > green and red > blue: print("Your dot's color has been classified as red!") else: print("Unfortunately, your dot could not be classified. Try picking a different number of closest dots next time.")

Turtle Graphics: drawing a house

from turtle import * bgcolor("salmon") color("black") shape("turtle") forward(200) right(90) forward (200) right (90) forward (200) right (90) forward(200) right(45) forward (150) right(95) forward (150) penup() right (90) forward (100) left (45) pendown() forward (25) left(90) forward (25) left(90) forward (25) left (90) forward (25) penup() forward (60) left (90) pendown() left(90) forward (25) right (90) forward (25) right(90) forward (25) right(90) forward (25) right (180) penup() forward (100) left (90) forward (40) pendown () forward (20) left (90) forward (35) left (90) forward (20) left (90) forward (35)

Rock, Paper, Scissors.

import random while True: number = random.randint(1, 3) str_number = int(input("choose (1) rock (2) paper or (3)scissors")) if str_number == number: print("Tie!") elif str_number == 1 and number == 2: print("You lose!") elif str_number == 1 and number == 3: print("You win!") print("Your opponent picked") elif str_number == 2 and number == 1: print("You win!") elif str_number == 2 and number == 3: print("You lose!") elif str_number == 3 and number == 1: print("You lose!") elif str_number == 3 and number == 2: print("You win!") if number == 1: print("Your opponent chose rock") if number == 2: print("Your opponent chose paper") if number == 3: print("Your opponent chose scissors") str_m = input("Do you want to play again?(yes or no)") if str_m == "no": print("bye") break

Coding Things

Stuff

#write a program that produces the following output. the user is asked to input any number. number=int(input("Put in any number: ")) f=number*6 if f>=600: print("Your number is too high. Put in another number.") elif f<=600: print("Your answer is "+str(f)) #Ask the user to input an amount in days. Convert number of days to seconds. Hint: Convert days to hours, hours to minutes, minutes to seconds day=int(input("Please put in a number of days that you want to convert to seconds: ")) x=day*24 y=x*60 z=y*60 print("It is "+str(z)+"seconds.") #write a python program which iterates the integers from 1 to 50. for multiples of three print "fizz" instead of the number and for the multiples of five print "Buzz". #For numbers which are multiples of both three and five print "FizzBuzz" for x in range(0,51,1): if x%3==0 and x%5==0: print("FizzBuzz") elif x%5==0: print("Buzz") elif x%3==0: print("Fizz") #write a python statement to find those numbers which are divisible by 7 and divisible by 5, between 1500 to 2700 for x in range(1499,2701,1): if x%7==0 and x%5==0: print(x) #print statements print("Hello") #Creating variables x=10 name="Rosie" #ask the user for input school=input("What is your school name?") print("I go to "+school) #collecting whole numbers from the user number=int(input("Enter a whole number:")) #Collecting decimal numbers number2=float(input("Enter a decimal:")) # 1)create a while loop from 1 to 150 skipping by 5 number=0 while number <= 150: print(number) number=number+5 # 2)create a for loop from 1 to 150 skipping by 3 for x in range(0,150,3): print(x) # 3)create a while loop from 1 to 200 printing all numbers except multiples of 4 for x in range(2,101,1): if x%4!=0: print(x) # 4)create a program which will ask for your recent exam score out of 60 and tell you what grade you got #A-90% and above #B-80% to 89.9 #C-70% to 79.99% number3=float(input("Enter your test score out of 60 using decimals:")) x=number3/60 y=x*100 print(y) if y>90: print("You got an A! Good Job!") elif y>80 and y<89.99: print("You got a B! Good Job") elif y>70 and y<79.99: print("You got a C! Good Job") elif y>60 and y<69.99: print("You got a D! Try Harder Next Time") elif y<59.9999: print("You got a F! You failed the test!") #write a Python program to calculate a dog's age in dog years #For the first 2 years, a dog year is equal to 10.5 years. #after that, it equals 4 years number4=float(input("Please enter your dog's age in decimals:")) if number4<=2.999999999: y=number4*10.5 print(y) print("Your dog's age is "+str(y)) elif number4>=3: z=number4*4 c=z+10.5*2 print(c) print("Your dog's age is "+str(c)) #Write a python program that asks the user to input a whole number in a variable called numb1. then the program prints everything from 1 to numb1 Numb1=int(input("Please insert a number: ")) for r in range(0,Numb1,1): print(r)

Rock Paper Scissors

Using if statements

var list =["R","P","S"]; var list =["R","P","S"]; var won = 0; var lost = 0; var draw =0; function rps(games){ var list =["R","P","S"]; var won = 0; var lost = 0; var draw = 0; for(i=0;i<games;i++){ var user = prompt("R(rock) P(paper) or S(scissors)?:"); var cpu = list[Math.floor(Math.random()*3)]; console.log("The computer played "+cpu); if (user == "R"){ if (cpu == "P"){ console.log("CPU wins"); lost +=1; won+=0; draw+=0; }else if (cpu == "S"){ console.log("You win!"); won+=1; lost+=0; draw+=0; }else if (cpu == "R"); console.log ("Its a draw"); draw+=1; won+=0; lost+=0; }else if (user == "P"){ if (cpu == "P"){ console.log("Its a draw"); draw +=1; won+=0; lost+=0; }else if(cpu=="R"){ console.log("You win!"); won+=1; lost+=0; draw+=0; }else if(cpu == "S"){ console.log("You lose!"); lost+=1; won+=0; draw+=0; } }else if (user == "S"){ if(cpu=="S"){ console.log("Its a draw"); draw+=1; won+=0; lost+=0; }else if (cpu =="P"){ console.log("You win!"); won+=1; lost+=0; draw+=0; }else if (cpu == "R"){ console.log("You lose!"); lost +=1 draw+=0; won+=0; } }else{ console.log("Undefined") } if (won<lost){ console.log("CPU wins! Cpu won "+lost+" games!") }else if (lost<won){ console.log("You win! You won " +won+ " games") } } } rps(10)

Cats and a Mouse problem solution using Python

#cats and a mouse problem #x=position of cat A #y=position of cat B #Z=position of mouse q=int(input()) for i in range(q): x,y,z =input().strip().split(' ') x,y,z=[int(x),int(y),int(z)] if abs(x-z)>abs(y-z): print("cat B") elif abs(x-z)<abs(y-z): print("cat A") else: print("Mouse")

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)

Aarush's House (Black and White)

This is my 3rd project and my first project using the turtle software in python.

from turtle import * screen = Screen() screen.setup (800,800) penup () goto (-300,-300) pendown () for x in range (4): forward (300) left (90) penup () goto (0,0) pendown () goto (-150, 100) goto (-300, 0) penup () goto (-120,-300) pendown () left (90) forward (100) left (90) goto (-180,-200) left (90) goto (-180, -300) penup () goto (-140, -250) pendown () for x in range (360): forward (1/10) left (1) penup () goto (-75, -50) pendown () for x in range (4): forward (45) left (90) penup () goto (-225, -50) pendown () for x in range (4): forward (45) right (90) penup () goto (-247.5,-50) pendown () goto (-247.5,-95) penup () goto (-270,-72.5) pendown () left (90) forward (45) penup () forward (150) pendown () goto (-75,-72.5) goto (-30,-72.5) penup () goto (-52.5, -50) pendown () goto (-52.5, -95) pendown ()

Calculator Layout

Tic Tac Toe game

from tkinter import * def click(r,c): global usr global gamestatus if(usr=='X' and grd[r][c]==0 and gamestatus==True): grd[r][c]='X' usr='O' curr[r][c].configure(text='X',bg="white") if(usr=='O' and grd[r][c]==0 and gamestatus==True): grd[r][c]='O' usr='X' curr[r][c].configure(text='O',bg="gray") checkWin() def checkWin(): global gamestatus for i in range(3): if grd[0][i]==grd[1][i]==grd[2][i]!=0: for j in range(3): curr[j][i].config(bg="snow4",fg="white") gamestatus=False for i in range(3): if grd[i][0]==grd[i][1]==grd[i][2]!=0: for j in range(3): curr[i][j].config(bg="snow4",fg="white") gamestatus=False if grd[0][2]==grd[1][1]==grd[2][0]!=0: curr[0][2].config(bg="snow4",fg="white") curr[1][1].config(bg="snow4",fg="white") curr[2][0].config(bg="snow4",fg="white") gamestatus=False if grd[0][0]==grd[1][1]==grd[2][2]!=0: for j in range(3): curr[j][j].config(bg="snow4",fg="white") gamestatus=False root=Tk() root.title("ProjectGurukul Tic Tac Toe") usr="O" gamestatus=True grd=[[0,0,0], [0,0,0], [0,0,0]] curr=[[0,0,0], [0,0,0], [0,0,0]] for i in range(3): for j in range(3): curr[i][j]=Button(font=('arial',30,'bold'),width=4, command=lambda r=i, c=j:click(r,c)) curr[i][j].grid(row=i,column=j) mainloop()
1 2 ... 46
Announcements
  • Test Announcement from Nexclap

    Test message from nexclap - please ignore

    2023-02-13

  • Test message

    Test message from nexclap - please ignore

    2023-02-11

  • Test message

    Test message from nexclap - please ignore

    2023-02-11

  • View all