Skip to content

Instantly share code, notes, and snippets.

View anmolj7's full-sized avatar

Anmol Jhamb anmolj7

View GitHub Profile
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 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)
#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,