This file contains hidden or 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 hidden or 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 hidden or 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, |
NewerOlder