This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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: ") |
OlderNewer