Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My Contribution to this Repository #13

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions solutions/Rishav Mitra/Code/ToDo App/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__

*.db
50 changes: 50 additions & 0 deletions solutions/Rishav Mitra/Code/ToDo App/backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This file contains all the functions that will be used in the app
import sqlite3

def createTable():
conn = sqlite3.connect('tasksDatabase.db')
c = conn.cursor()

c.execute("""CREATE TABLE tasks(
id integer primary key autoincrement,
name text,
status text)""")

conn.commit()
conn.close()

def addNewTask(task):
conn = sqlite3.connect('tasksDatabase.db')
c = conn.cursor()

c.execute("INSERT INTO tasks (name, status) VALUES (?, ?)", (task, 'pending'))

conn.commit()
conn.close()

def markTaskAsDone(idc):
conn = sqlite3.connect('tasksDatabase.db')
c = conn.cursor()

c.execute("UPDATE tasks SET status = 'done' WHERE id = (?)", (idc, ))

conn.commit()
conn.close()

def removeDoneTask():
conn = sqlite3.connect('tasksDatabase.db')
c = conn.cursor()

c.execute("DELETE from tasks WHERE status = 'done'")

conn.commit()
conn.close()

def showAllTasks():
conn = sqlite3.connect('tasksDatabase.db')
c = conn.cursor()

c.execute("SELECT * FROM tasks")

rows = c.fetchall()
return rows
66 changes: 66 additions & 0 deletions solutions/Rishav Mitra/Code/ToDo App/taskManagerSqlite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import backend # This is the local file called 'backend.py'
import os
from tkinter import *

root = Tk()
root.geometry("620x450")
root.title("To Do App")

if not os.path.exists('tasksDatabase.db'):
backend.createTable()

# Implement the basic functionalities
def add():
task = newTaskEntry.get()
backend.addNewTask(task)
show()

def done():
try:
idc = doneEntry.get()
backend.markTaskAsDone(idc)
except Exception as e:
doneEntry.insert("end", "Something was wrong")
finally:
show()

def remove():
backend.removeDoneTask()
show()

def show():
tasks.delete(1.0, END)
rows = backend.showAllTasks()
if len(rows) == 0:
tasks.insert("end", "No tasks added")
else:
for row in rows:
tasks.insert("end", f"{row[0]} | {row[1]} | {row[2]} \n\n")

# Create the layout
newTaskLabel = Label(root, text = "Add a new task")
newTaskLabel.grid(row = 0, column = 0, padx = 40)

newTaskEntry = Entry(root, font = "Arial")
newTaskEntry.grid(row = 1, column = 0, padx = 25, ipady = 5)

addTaskBtn = Button(root, text = "Add", command = add)
addTaskBtn.grid(row = 1, column = 1, ipadx = 5)

tasks = Text(root, height = 20, width = 40, font = "Arial")
tasks.grid(row = 2, column = 0, rowspan = 4, padx = 10, pady = 10)

doneLabel = Label(root, text = "Enter the id of any task you've completed")
doneLabel.grid(row = 2, column = 1)

doneEntry = Entry(root, font = "Arial")
doneEntry.grid(row = 3, column = 1)

okBtn = Button(root, text = "OK", command = done)
okBtn.grid(row = 4, column = 1)

removeBtn = Button(root, text = "Remove Done Tasks", command = remove)
removeBtn.grid(row = 5, column = 1)

show()
root.mainloop()
62 changes: 62 additions & 0 deletions solutions/Rishav Mitra/Code/bmi_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from tkinter import *

# Define the available units
massUnitOptions = ["kg", "lb"]
heightUnitOptions = ["m", "cm", "inches"]

root = Tk()
root.title("BMI Calculator")
root.geometry("500x300")

# submit() function performs the necessary calculations
def submit():
mass = float(massInput.get())
height = float(heightInput.get())
mass_unit = massUnits.get()
height_unit = heightUnits.get()

if mass_unit == "lb":
mass /= 2.205
if height_unit == "cm":
height /= 100
if height_unit == "inches":
height /= 39.37

bmi = mass/(height**2)
bmiLabel.config(text = round(bmi, 3))

massUnits = StringVar()
massUnits.set(massUnitOptions[0])

heightUnits = StringVar()
heightUnits.set(heightUnitOptions[0])

# arrange all the widgets on the screen
massLabel = Label(root, text = "Enter your weight :", font = "bold")
massLabel.grid(row = 0, column = 0, padx = 35, pady = 20)

massInput = Entry(root, justify = "center", font = "bold")
massInput.grid(row = 0, column = 1)

massOptions = OptionMenu(root, massUnits, *massUnitOptions)
massOptions.grid(row = 0, column = 2, padx = 5)

heightLabel = Label(root, text = "Enter your height :", font = "bold")
heightLabel.grid(row = 1, column = 0)

heightInput = Entry(root, justify = "center", font = "bold")
heightInput.grid(row = 1, column = 1)

heightOptions = OptionMenu(root, heightUnits, *heightUnitOptions)
heightOptions.grid(row = 1, column = 2, padx = 5)

submitBtn = Button(root, text = "OK", command = submit, padx = 10)
submitBtn.grid(row = 2, column = 0, columnspan = 2, pady = 25)

info = Label(root, text = "Your Body Mass Index (BMI) is", font = "bold")
info.grid(row = 3, column = 0, columnspan = 2)

bmiLabel = Label(root, text = "", font = "bold")
bmiLabel.grid(row = 4, column = 0, columnspan = 2)

root.mainloop()
55 changes: 55 additions & 0 deletions solutions/Rishav Mitra/Code/caesar_cipher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This is a command-line application
import string

# Getting the list of alphabets
UPPERCASE_LETTERS = string.ascii_uppercase
LOWERCASE_LETTERS = string.ascii_lowercase

# function to encrypt the message
def encrypt(message, shift):
encrypted_message = ""
# Algorithm for encryption
for char in message:
if char in UPPERCASE_LETTERS:
new_char = UPPERCASE_LETTERS[(UPPERCASE_LETTERS.index(char) + shift) % 26]
elif char in LOWERCASE_LETTERS:
new_char = LOWERCASE_LETTERS[(LOWERCASE_LETTERS.index(char) + shift) % 26]
else:
new_char = char

encrypted_message += new_char

return encrypted_message

# function to decrypt the message
def decrypt(message, shift):
decrypted_message = ""
# Algorithm for decryption
for char in message:
if char in UPPERCASE_LETTERS:
new_char = UPPERCASE_LETTERS[(UPPERCASE_LETTERS.index(char) - shift) % 26]
elif char in LOWERCASE_LETTERS:
new_char = LOWERCASE_LETTERS[(LOWERCASE_LETTERS.index(char) - shift) % 26]
else:
new_char = char

decrypted_message += new_char

return decrypted_message

if __name__ == '__main__':
option = input("Do you want to [e]ncrypt or [d]ecrypt your message ? ")

if option in ['e', 'd']:
message = input("Enter your message : ")

print("Enter the shift of the cipher \nPositive values => Right shift \nNegative values => Left shift")
shift = int(input())

if option == 'e':
print(encrypt(message, shift))
elif option == 'd':
print(decrypt(message, shift))

else:
print("Please enter a valid option !")
20 changes: 20 additions & 0 deletions solutions/Rishav Mitra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@Rishav-12
Rishav Mitra

* I have a few of my own projects on GitHub. This is my first contribution to an Open-source GitHub project
* My GitHub Link : www.github.com/Rishav-12

### About the Code
* BMI Calculator:
* It basically takes in the weight and the height which the user inputs, and displays their Body Mass Index (BMI)
* It is a GUI-based application made with Tkinter

* Caesar Cipher:
* It has two functions, one to encrypt and the other to decrypt the message
* The users decide whether they want to encrypt or decrypt their message, type in the message and the shift value, and the program generates the appropriate encrypted/decrypted message
* This is a command line interface application

* ToDo App:
* A fully functional to-do list application with a front-end UI and a SQLite3 back-end
* Maintains a database that contains a table with all the tasks and their current status
* Has all the basic functions of a to-do application like adding tasks, marking tasks as done and removing them from the database