Skip to content

Instantly share code, notes, and snippets.

View anmolj7's full-sized avatar

Anmol Jhamb anmolj7

View GitHub Profile
#Not using float because the we're multiplying not dividng, in multiplying, the end result will always be a whole number.
def factorial(number):
return 1 if number < 2 else number * factorial(number-1)
#Used number < 2 instead of number == 1 or number == 0, It's shorter.
try:
number = int(input("Enter A Number: ")) #Converting To Int cause we can find factorial
#of only integer and not decimal values ..
except ValueError:
#If the user types some other type of data, for example
#He enters string, we obviously can't find the factorial of string,
#This code is written and tested in python 2.7
#The library NLTK has to be installed first.
import re, nltk, heapq
class Summary:
def summary(self, article_text, n=5): # n indicates the number of lines of summary required
# article_text = re.sub(r'\[[0-9]*\]', ' ', text)
# article_text = re.sub(r'\s+', ' ', article_text)
formatted_article_text = re.sub('[^a-zA-Z]', ' ', article_text )
formatted_article_text = re.sub(r'\s+', ' ', formatted_article_text)
sentence_list = nltk.sent_tokenize(article_text)
def intInput():
return int(input())
def listInput():
A = input().split()
A = [int(x) for x in A]
return A
T = intInput()
for x in range(T):
#this code was tested and working on python 3.6.5
#The Module TextBlob Needs To Be Installed as it contains a predefined function that
#can calculate the polarities. It includes a list of words that has a list of certain value ..
from textblob import TextBlob
text = input("Enter The Text> ")
model = TextBlob(text)
print(model.sentiment.polarity)
#The Polarity ranges from -1 to 1
from nltk.classify import NaiveBayesClassifier
from nltk.corpus import subjectivity
from nltk.sentiment import SentimentAnalyzer
from nltk.sentiment.util import *
from nltk.sentiment.vader import SentimentIntensityAnalyzer
import nltk, re
class Polarity:
def __init__(self):
from __future__ import print_function, division, unicode_literals
import os
import errno
from collections import Counter
from hashlib import sha256
import re
import json
import itertools
import logging
@anmolj7
anmolj7 / jarvis-old.py
Created January 29, 2019 21:01
The oldest version of Jarvis I could Find....
import subprocess as sp
import omdb
import wikipedia
import wolframalpha
import serial
import time
ser = serial.Serial('COM3', baudrate = 9600, timeout=1)
time.sleep(3)
def getValues():
ser.write(b'g')
from PIL import Image, ImageDraw, ImageFont
import os
Class = input("Enter Class In Roman Numerals: ")
Class = Class.upper.strip()
section = input("Section:")
os.chdir('{0}{1}'.format(Class, section))
files = os.listdir(os.getcwd()) #Listing All The Files
#Selecting Only JPEG Files ...
import os
print("Python Program to print list the files in a directory.")
Direc = input(r"Enter the path of the folder: ")
print(f"Files in the directory: {Direc}")
files = os.listdir(Direc)
files = [f for f in files if os.path.isfile(Direc+'/'+f)] #Filtering only the files.
print(*files, sep="\n")
'''
Write a Python script to search for text in a file and replace it, for example, there is a text file that reads Hello World, change it to Hello name. The intended output is the link to the gist.
'''
fName = input("Enter the file's name: ")
with open(fName) as f:
data = f.read()
repl = input("Enter the text to be replaced: ")
word = input(f"Replace {repl} to: ")