Skip to content

Instantly share code, notes, and snippets.

@shinysu
shinysu / 0_Session3.py
Last active October 30, 2020 05:53
Simple programs
'''
print a string
'''
print("hello!")
@shinysu
shinysu / 0_Session5.py
Last active November 13, 2020 13:37
programs using loops
'''
using for loop to print numbers 1 to 10
range(a, b+1) starts from a and ends at b
'''
for i in range(1, 11):
print(i)
@shinysu
shinysu / 0_lists.py
Last active November 18, 2020 12:26
Examples & exercises using list
'''
check if an element is present in the list
you can use 'in' operator to check if the element is present and 'not in' operator to check if the element is not present
'''
cart = ['ice cream', 'chocolates', 'bread', 'jam', 'butter']
item = input("Enter the element you want to search: ")
if item in cart:
print("yes, the element is present")
@shinysu
shinysu / 0_Session6.py
Last active November 3, 2020 08:52
Programs using files
'''
program to read from a file using read() and write to another file using write()
'''
with open("input.txt","r") as reader:
lines = reader.read()
with open("output.txt","w") as writer:
writer.write(lines)
@shinysu
shinysu / file_ops.py
Last active November 7, 2020 07:28
ToDolist using PySimpleGUI and files
def file_write(fname, tasks):
with open(fname, "w") as fp:
for x in tasks:
fp.write("%s\n" % x)
def file_read(fname):
tasks = []
try:
with open(fname, "r") as fp:
@shinysu
shinysu / bot.py
Created November 7, 2020 11:00
Wordbot using wordnet
"""
bot.py : Given a word, gets the meaning, synonyms and antonyms for the word
"""
import PySimpleGUI as sg
from utils import get_meaning
greeting = "Hi, I am a word bot. I can help you with words\n"
layout = [
[sg.Multiline(greeting, font=("Arial", 14), size=(70, 15), key='output')],
@shinysu
shinysu / bot.py
Created November 21, 2020 14:03
Web Page Analyser
import PySimpleGUI as sg
from webutils import get_html_content, parse_html_using_tag
from utils import get_statistics
layout = [
[sg.Text("Web Page Analyzer", font=("Arial", 18))],
[sg.Text("Enter URL", font=("Arial", 14)), sg.InputText("", font=("Arial", 14), key='url'),
sg.Button("Get Data", font=("Arial", 14), key='get')],
[sg.Multiline("", font=("Arial", 14), size=(60, 15), key='output')]
]
@shinysu
shinysu / bot.py
Last active November 29, 2020 04:53
Web Page Analyzer
"""
bot.py : Given an url, analyses the webpage and gives the following information about the page
1. Number of sentences in the webpage
2. Number of words in the page
3. Number of unique words in the page
4. 5 most frequent words in the page
"""
import PySimpleGUI as sg
from webutils import get_content_from_url, parse_html_by_tags
@shinysu
shinysu / create_db.py
Created December 4, 2020 09:22
Todolist using SQLite database
'''
create_db.py - creates the table.
Note: This program should be run first to create the database and tables
'''
import sqlite3
def create_table():
sql_query = """
CREATE TABLE tasks(
@shinysu
shinysu / create_db.py
Last active December 5, 2020 11:42
Todolist_SQLite
'''
create_db.py - creates the table.
Note: This program should be run first to create the database and tables
'''
import sqlite3
def create_table():
sql_query = """
CREATE TABLE tasks(