# I understand that this isn't Grepper's primary use but here are some
# fun little projects that I've found (self taught) to be really fun and
# educational!
def beginner():
# Beginner Projects
beginner_proj ="""
Everyone has to start somewhere!
Understand functions with a simple math function
- Takes in an input, makes it an integer, multiplies it by 2, returns/prints result
Same string checker
- Takes in two strings and compares them. If they're the same, print("Same!")
String character counter
- Takes in a string and outputs the length of the string
-- Bonus points if you can make it not count spaces!
Coinflipper
- Use Python's random module to select a random num between 0-1. If it's 0, it's tails else it's heads
-- Bonus points if you can take in a user input of heads/tails and compare that to
-- the flip, letting them know if they won or not
Test percentage calculator
- Take in test result and total test score then do simple maths to find the percentage
-- Bonus points if you can find out how to round the percentage
Number guessing game
- Generate number from 0-100 and ask the user to guess the number
-- Many bonus points if you can create a points system!
Make a random person picker for a party game
- Using Python's random module, choose a random person from a list of names
-- Bonus points if you make a menu at the beginning of the game
-- which allows users to add many names
"""
print(beginner_proj)
def intermediate():
# Intermediate Projects
intermediate_proj ="""
Well done, you're doing well!
Create a quadratic equation solver
- Sounds difficult but just google quadratic equation and take in the values a, b and c
- This will teach you about Python's math module
Make a benchmark
- Using pythons time module, start a timer on the first line, make the program do many complex
- calculations (e.g multiply all numbers from 0-1mil by 2) and when finished, stop the timer.
- print out the time taken
Make a morse code translator
- Test your knowledge of dictionaries with a dictionary that compares
- {"letter":"more_code"}. Then loop through an inputted string and convert it into morse
Make your first API call
- Using the Requests module, send a request to "https://api.genderize.io/?name=your_name"
- and by using formatted strings, replace your_name with an inputted name! Output the guessed gender.
Make an information generator
- Make a program that will generate a: name, email, address, tel num, height, ethnicity, eye colour etc.
-- Bonus points if you can store the generated person in a dictionary so that you can access information about
-- them at any time
Make a complete casino
- Coinflip, roulette, slots etc.
-- Bonus points if you can integrate a deposit money feature (Obviously fake money!)
"""
print(intermediate_proj)
def expert():
# Expert projects
expert_proj = """
Ah, I see you're bored and want some ideas on what to do next
Create a Discord bot using discord.py
- The community is incredibly supportive and it's something that can be quite fun!
- Make a bot that can: ban, kick, warn, say anything, change nicknames etc.
Create your own PYPI package
- Making a python module is an impressive feat, why not try it out?
- Think it's too hard? I managed to make mine when I was just 16 and trust me, I just followed
- the official documentation line by line!
Make a text based game
- Include minigames and an interesting story
Make an edge detection algorithm
- This one is quite tough but I'm 17 and have managed so I'm sure you can too!
- An edge is detected by getting the average of the neighbouring pixels to a pixel
- and then finding the average of those pixels. Subtract that average from the current pixel.
-- For a solution visit my method (Definitely not the best way of doing it)
-- https://github.com/pTinosq/Edge-Detection-Algorithm
Make a noise reduction algorithm
- Also quite difficult but possible
- Noise is reduced in a very similar way but instead of subtracting the mean, you replace the
- current pixel with the mean you just calculated
-- Answer also available at https://github.com/pTinosq/Noise-Reduction-Algorithm
I know you won't particularly like this one but, try something new!
If you think you've mastered python well enough, try and expand your horizons.
Here are some languages you might consider:
Javascript, HTML/CSS, LUA, C#, Kotlin, Rust, GO, Swift
"""
print(expert_proj)
def final_notes():
thank_you = """
Thanks for taking the time to read this, I hope it gave some of you some good ideas to work with!
If you're interested in seeing some of the projects being put to use, check out my Github
https://github.com/pTinosq where I will post most of my new projects (Unless they're private).
"""
print(thank_you)
# How to Perform Motion Detection Using Python
# Importing the Pandas libraries
import pandas as panda
# Importing the OpenCV libraries
import cv2
# Importing the time module
import time
# Importing the datetime function of the datetime module
from datetime import datetime
# Assigning our initial state in the form of variable initialState as None for initial frames
initialState = None
# List of all the tracks when there is any detected of motion in the frames
motionTrackList= [ None, None ]
# A new list 'time' for storing the time when movement detected
motionTime = []
# Initialising DataFrame variable 'dataFrame' using pandas libraries panda with Initial and Final column
dataFrame = panda.DataFrame(columns = ["Initial", "Final"])
# starting the webCam to capture the video using cv2 module
video = cv2.VideoCapture(0)
# using infinite loop to capture the frames from the video
while True:
# Reading each image or frame from the video using read function
check, cur_frame = video.read()
# Defining 'motion' variable equal to zero as initial frame
var_motion = 0
# From colour images creating a gray frame
gray_image = cv2.cvtColor(cur_frame, cv2.COLOR_BGR2GRAY)
# To find the changes creating a GaussianBlur from the gray scale image
gray_frame = cv2.GaussianBlur(gray_image, (21, 21), 0)
# For the first iteration checking the condition
# we will assign grayFrame to initalState if is none
if initialState is None:
initialState = gray_frame
continue
# Calculation of difference between static or initial and gray frame we created
differ_frame = cv2.absdiff(initialState, gray_frame)
# the change between static or initial background and current gray frame are highlighted
thresh_frame = cv2.threshold(differ_frame, 30, 255, cv2.THRESH_BINARY)[1]
thresh_frame = cv2.dilate(thresh_frame, None, iterations = 2)
# For the moving object in the frame finding the coutours
cont,_ = cv2.findContours(thresh_frame.copy(),
cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for cur in cont:
if cv2.contourArea(cur) < 10000:
continue
var_motion = 1
(cur_x, cur_y,cur_w, cur_h) = cv2.boundingRect(cur)
# To create a rectangle of green color around the moving object
cv2.rectangle(cur_frame, (cur_x, cur_y), (cur_x + cur_w, cur_y + cur_h), (0, 255, 0), 3)
# from the frame adding the motion status
motionTrackList.append(var_motion)
motionTrackList = motionTrackList[-2:]
# Adding the Start time of the motion
if motionTrackList[-1] == 1 and motionTrackList[-2] == 0:
motionTime.append(datetime.now())
# Adding the End time of the motion
if motionTrackList[-1] == 0 and motionTrackList[-2] == 1:
motionTime.append(datetime.now())
# In the gray scale displaying the captured image
cv2.imshow("The image captured in the Gray Frame is shown below: ", gray_frame)
# To display the difference between inital static frame and the current frame
cv2.imshow("Difference between the inital static frame and the current frame: ", differ_frame)
# To display on the frame screen the black and white images from the video
cv2.imshow("Threshold Frame created from the PC or Laptop Webcam is: ", thresh_frame)
# Through the colour frame displaying the contour of the object
cv2.imshow("From the PC or Laptop webcam, this is one example of the Colour Frame:", cur_frame)
# Creating a key to wait
wait_key = cv2.waitKey(1)
# With the help of the 'm' key ending the whole process of our system
if wait_key == ord('m'):
# adding the motion variable value to motiontime list when something is moving on the screen
if var_motion == 1:
motionTime.append(datetime.now())
break
# At last we are adding the time of motion or var_motion inside the data frame
for a in range(0, len(motionTime), 2):
dataFrame = dataFrame.append({"Initial" : time[a], "Final" : motionTime[a + 1]}, ignore_index = True)
# To record all the movements, creating a CSV file
dataFrame.to_csv("EachMovement.csv")
# Releasing the video
video.release()
# Now, Closing or destroying all the open windows with the help of openCV
cv2.destroyAllWindows()
# Python Calculator
from tkinter import *
root = Tk()
root.geometry("500x500")
root.resizable(0, 0)
root.title('Python Calculator')
expression = ""
input_text = StringVar()
# clear
def btn_clear():
global expression
expression = ""
input_text.set("")
# click
def btn_click(item):
global expression
expression = expression + str(item)
input_text.set(expression)
# calculate
def btn_equal():
global expression
result = str(eval(expression))
input_text.set(result)
expression = ""
# input frame
input_frame = Frame(root, width=312, height=50, bd=0,
highlightbackground="black", highlightcolor="black",
highlightthickness=2)
input_frame.pack(side=TOP)
# input field inside the frame
input_field = Entry(input_frame, font=('arial', 18, 'bold'),
textvariable=input_text, width=50, bg="#eee", bd=0, justify=RIGHT)
input_field.grid(row=0, column=0)
input_field.pack(ipady=10)
# button frame
btns_frame = Frame(root, width=312, height=272.5, bg="grey")
btns_frame.pack()
# first row
clear = Button(btns_frame, text="CLEAR", fg="black", width=32,
height=3, bd=0, bg="#eee", cursor="hand2", command=lambda:
btn_clear()).grid(row=0, column=0, columnspan=3, padx=1, pady=1)
divide = Button(btns_frame, text="/", fg="black", width=10,
height=3, bd=0, bg="#eee", cursor="hand2", command=lambda:
btn_click("/")).grid(row=0, column=3, padx=1, pady=1)
# second row
seven = Button(btns_frame, text="7", fg="black", width=10,
height=3, bd=0, bg="#fff", cursor="hand2", command=lambda:
btn_click(7)).grid(row=1, column=0, padx=1, pady=1)
eight = Button(btns_frame, text="8", fg="black", width=10,
height=3, bd=0, bg="#fff", cursor="hand2", command=lambda:
btn_click(8)).grid(row=1, column=1, padx=1, pady=1)
nine = Button(btns_frame, text="9", fg="black", width=10, height=3, bd=0, bg="#fff", cursor="hand2", command=lambda:
btn_click(9)).grid(row=1, column=2, padx=1, pady=1)
multiply = Button(btns_frame, text="*", fg="black", width=10,
height=3, bd=0, bg="#eee", cursor="hand2", command=lambda:
btn_click("*")).grid(row=1, column=3, padx=1, pady=1)
# third row
four = Button(btns_frame, text="4", fg="black", width=10, height=3, bd=0, bg="#fff", cursor="hand2", command=lambda:
btn_click(4)).grid(row=2, column=0, padx=1, pady=1)
five = Button(btns_frame, text="5", fg="black", width=10, height=3, bd=0, bg="#fff", cursor="hand2", command=lambda:
btn_click(5)).grid(row=2, column=1, padx=1, pady=1)
six = Button(btns_frame, text="6", fg="black", width=10, height=3, bd=0, bg="#fff", cursor="hand2", command=lambda:
btn_click(6)).grid(row=2, column=2, padx=1, pady=1)
minus = Button(btns_frame, text="-", fg="black", width=10,
height=3, bd=0, bg="#eee", cursor="hand2", command=lambda:
btn_click("-")).grid(row=2, column=3, padx=1, pady=1)
# fourth row
one = Button(btns_frame, text="1", fg="black", width=10, height=3, bd=0, bg="#fff", cursor="hand2", command=lambda:
btn_click(1)).grid(row=3, column=0, padx=1, pady=1)
two = Button(btns_frame, text="2", fg="black", width=10, height=3, bd=0, bg="#fff", cursor="hand2", command=lambda:
btn_click(2)).grid(row=3, column=1, padx=1, pady=1)
three = Button(btns_frame, text="3", fg="black", width=10,
height=3, bd=0, bg="#fff", cursor="hand2", command=lambda:
btn_click(3)).grid(row=3, column=2, padx=1, pady=1)
plus = Button(btns_frame, text="+", fg="black", width=10, height=3, bd=0, bg="#eee", cursor="hand2", command=lambda:
btn_click("+")).grid(row=3, column=3, padx=1, pady=1)
# fourth row
zero = Button(btns_frame, text="0", fg="black", width=21, height=3, bd=0, bg="#fff", cursor="hand2", command=lambda:
btn_click(0)).grid(row=4, column=0, columnspan=2, padx=1, pady=1)
point = Button(btns_frame, text=".", fg="black", width=10,
height=3, bd=0, bg="#eee", cursor="hand2", command=lambda:
btn_click(".")).grid(row=4, column=2, padx=1, pady=1)
equals = Button(btns_frame, text="=", fg="black", width=10,
height=3, bd=0, bg="#eee", cursor="hand2", command=lambda:
btn_equal()).grid(row=4, column=3, padx=1, pady=1)
root.mainloop()
# Python Snake Game
import pygame
import time
import random
pygame.init()
white = (255, 255, 255)
yellow = (255, 255, 102)
black = (0, 0, 0)
red = (213, 50, 80)
green = (0, 255, 0)
blue = (50, 153, 213)
dis_width = 600
dis_height = 400
dis = pygame.display.set_mode((dis_width, dis_height))
pygame.display.set_caption('Snake Game')
clock = pygame.time.Clock()
snake_block = 10
snake_speed = 10
font_style = pygame.font.SysFont("bahnschrift", 25)
score_font = pygame.font.SysFont("comicsansms", 35)
def Your_score(score):
value = score_font.render("Your Score: " + str(score), True, yellow)
dis.blit(value, [0, 0])
def our_snake(snake_block, snake_list):
for x in snake_list:
pygame.draw.rect(dis, black, [x[0], x[1], snake_block, snake_block])
def message(msg, color):
mesg = font_style.render(msg, True, color)
dis.blit(mesg, [dis_width / 6, dis_height / 3])
def gameLoop():
game_over = False
game_close = False
x1 = dis_width / 2
y1 = dis_height / 2
x1_change = 0
y1_change = 0
snake_List = []
Length_of_snake = 1
foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0
foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0
while not game_over:
while game_close == True:
dis.fill(blue)
message("You Lost! Press C to Play Again or Q to Quit", red)
Your_score(Length_of_snake - 1)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
game_over = True
game_close = False
if event.key == pygame.K_c:
gameLoop()
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x1_change = -snake_block
y1_change = 0
elif event.key == pygame.K_RIGHT:
x1_change = snake_block
y1_change = 0
elif event.key == pygame.K_UP:
y1_change = -snake_block
x1_change = 0
elif event.key == pygame.K_DOWN:
y1_change = snake_block
x1_change = 0
if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0:
game_close = True
x1 += x1_change
y1 += y1_change
dis.fill(blue)
pygame.draw.rect(dis, green, [foodx, foody, snake_block, snake_block])
snake_Head = []
snake_Head.append(x1)
snake_Head.append(y1)
snake_List.append(snake_Head)
if len(snake_List) > Length_of_snake:
del snake_List[0]
for x in snake_List[:-1]:
if x == snake_Head:
game_close = True
our_snake(snake_block, snake_List)
Your_score(Length_of_snake - 1)
pygame.display.update()
if x1 == foodx and y1 == foody:
foodx = round(random.randrange(
0, dis_width - snake_block) / 10.0) * 10.0
foody = round(random.randrange(
0, dis_height - snake_block) / 10.0) * 10.0
Length_of_snake += 1
clock.tick(snake_speed)
pygame.quit()
quit()
gameLoop()