Skip to content

Update #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Python application

on: [push, pull_request]
jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
# pytest
12 changes: 6 additions & 6 deletions CompetitiveProgramming/CodeChef/P36_SUBGCD.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def gcd(firstNumber, secondNumber):
flag = 0
size = 0
for i in array:
currentGCD = gcd(i, currentGCD)
if currentGCD == 1:
flag = 1
print(count)
break
currentGCD = gcd(i, currentGCD)
if currentGCD == 1:
flag = 1
print(count)
break

if flag == 0:
print(-1)
print(-1)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import math

userInput = int(input())
if userInput>2
if userInput > 2:
print("2",end = ' ')
for i in range(3, userInput + 2):
check = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
array = input().split()
array = [int(i) for i in array]
array.insert(0,0)
count =
count = 0
for i in range(0, check + 1):
pos = array[i] + i
if pos > check:
Expand Down
4 changes: 2 additions & 2 deletions CompetitiveProgramming/SPOJ/P14_MUL.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
t = int(input())
while t>0:
t-=1
n1, n2 = map(int, raw_input().split())
print n1*n2
n1, n2 = map(int, input().split())
print(n1*n2)
38 changes: 38 additions & 0 deletions OOP/P11_Property decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#This shows the usage of property decorators

#Python @property is one of the built-in decorators. The main purpose of any decorator is to change your class methods or attributes in such a way so that the users neeed not make any additional changes in their code.

#Without property decorators

class BankAccount:
def __init__(self,name,balance):
self.name=name
self.balance=balance
self.total= self.name+ " has "+self.balance+ " dollars in the account"

user1=BankAccount("Elon Musk","10000")
user1.name="Tim cook"
print(user1.name)
print(user1.total)

# Output: Tim cook
# Elon Musk has 10000 dollars in the account


#With property decorators

class BankAccount:
def __init__(self,name,balance):
self.name=name
self.balance=balance
@property
def total(self):
return self.name+ " has "+self.balance+ " dollars in the account"

user1=BankAccount("Elon Musk","10000")
user1.name="Tim cook"
print(user1.name)
print(user1.total)

#Output: Tim cook
# Tim cook has 10000 dollars in the account
145 changes: 145 additions & 0 deletions Programs/Chatbot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# -*- coding: utf-8 -*-
import nltk
from nltk.chat.util import Chat, reflections

reflections = {
"i am" : "you are",
"i was" : "you were",
"i" : "you",
"i'm" : "you are",
"i'd" : "you would",
"i've" : "you have",
"i'll" : "you will",
"my" : "your",
"you are" : "I am",
"you were" : "I was",
"you've" : "I have",
"you'll" : "I will",
"your" : "my",
"yours" : "mine",
"you" : "me",
"me" : "you",

}
pairs = [
[
r"my name is (.*)",
["Hello %1, How are you today ?",]
],
[
r"hi|hey|hello",
["Hello", "Hey there",]
],
[
r"what is your name ?|your name|name please",
["I am Y2K. You can call me crazy individual!",]
],
[
r"how are you ?|how you doing|what about you|how about you ?",
["I'm doing good. How can I help you ?",]
],
[
r"sorry (.*)",
["Its alright","Its OK, never mind",]
],
[
r"I am fine",
["Great to hear that, How can I help you?",]
],
[
r"(.*) continents",
["Asia, Africa, North America, South America, Antarctica, Europe, and Australia ",]
],
[
r"(.*) (english|hollywood) movie",
["The Shawshank Redemption", " The Lord of the Rings: The Return of the King","Inception", "Interstellar", "Parasite", "Twilight", "Fast & Furious", "Lucky one","A walk to remember", "The Last Song", "The Notebook","The Fault in Our Stars", "Joker", "Me Before You", "All the boys have met before","Kissing booth", "Titanic",]
],
[
r"i'm (.*) doing good",
["Nice to hear that","How can I help you?:)",]
],
[
r"(.*) age?|are you an (idiot|stupid)|what do you think you are",
["I'm a computer program dude....Seriously you are asking me this?",]
],
[
r"(.*) (online|free) courses",
["Udemy","Udacity","Great Learning","Google Digital Garage","Swayam",]
],
[
r"(.*) (news channel|news)",
["BCC World News","Fox News","Cable News Network (CNN)","Sky News","MSNCB","Republic World","ZEE News","ABP News",]
],
[
r"(.*) (horror|spooky) movie",
["The Nun", "Annabelle", "The conjuring", "Sinister", "The cabin in the wood", "insidious", "IT","Ouija", "Train to Busan", "The Ring", "Hush", "Evil Dead", "Oculus",]
],
[
r"(.*) (bollywood|hindi) movie",
["War", "My name is Khan", "Happy new year", "Dilwale", "Uri", "Don", "Don 2", "Raees","Raazi", "Kalank", "Kalank", "Dangal", "LUDO", "Good Newz", "PK", "Jab Tak Hai Jaan","Cocktail", "Bahubali", "M.S.Dhoni", "Aashiqui 2","Dear Zindagi","Anand", "Mughal-E-Azam", "Mother India", "Don ", " Parinda", "Mr. India","Mera Naam Joker", "Amar, Akbar and Anthony", " Agneepath ", "Sahib Bibi Aur Ghulam","Sholay",]
],
[
r"(.*) (webseries|series)",
["You", "Lucifer", "Cursed", "Mismatched", "Money Heist", "Stranger Things", "Merlin","The Protector", "Sabrina", "Dark", "Friends", "The Big Bang Theory", "Little Things","Lock & Key", "Sherlock", "Sweet Tooth", "The Witcher", "Shadow and Bones","Never Have i ever", "Brooklyn Nine-Nine", "Ragnarok", "Originals", "Vampire Diaries","The Order", "The Boss Baby", "The Haunting of Hill House", "Pup Academy", "Mary Queen of Scots","Bitten", "Titans", "Warrior Nun","The Haunting of bly Manor",]
],
[
r"(.*) k-drama",
["descendants of the sun","busted", "her private life", "whats wrong with secretary kim","its okay to not be okay", "hospital playlist", "crash landing on you","weightlifting fairy kim bok joo", "my first first love", "beauty inside", "was it love",]
],
[
r"(.*) (novel|book)",
["Harry Potter", "Twilight", "Alchemist", "Angel And Demon", "Dead Beautiful", "Lost Symbol", "The Vinche Code", "Hunger Games",]
],
[
r"(.*) created ?",
["I am created using Python's NLTK library ","top secret",]
],
[
r"(.*) band",
["BTS", "The Beatles", "The rolling stones", "Maroon 5", "One Direction", "No Doubt","Black Pink", "EXO", "MonstaX", "Stray Kids","The chainsmokers",]
],
[
r"(.*) actress",
["Scarlett Johansson", "Jennifer Lawrence", "Emma Watson", " Margot Robbie","Angelina Jolie", "Kristen Stewart", "Rachel McAdams","Deepika Padukone", "Priyanka Chopra", "Alia Bhatt", "Kareena Kapoor","Nora Fatehi", "Jacqueline Fernandez", "Aishwarya Rai", "Sara Ali Khan", "Shraddha Kapoor","Anushka Sharma", "Disha Patani",]
],
[
r"(.*) (game|sport)",
["Cricket","Hockey", "Basketball", "Football", "Baseball","Badminton", "Tennis", "Swimming", "Archery","Skates", "Volleyball", "Table Tennis", "Golf",]
],
[
r"(.*) (sports person|player)",
["Lionel Messi","Sania Mirza", "Sachin Tendulkar", "Virat Kohli", "Kevin Durant","Hardik Pandya", "Rohit Sharma", "P. V. Sindhu", "Parupalli Kashyap","Sania Mirza", "Dhyan Chand", "Cristiano Ronaldo", "Robert Lewandowski","Chris Gayle", "Steve Smith", "David Warner", "Ricky Ponting","Stephen Curry", "LeBron James", "M.S.Dhoni", "Chris Paul",]
],
[
r"(.*) actor",
["Robert Downey, Jr.", "Chris Hemsworth", "Tom Holland", "Brad Pitt","Tom Hiddleston", "Tom Cruise", "Chris Evans", "Benedict Cumberbatch","Paul Rudd", "Jeremy Renner", "Ian Somerhalder ","Paul Wesley", "Aamir Khan", "Amitabh Bachchan","Anil Kapoor", "Ranveer Singh", "Ranbir Kapoor", "Salman Khan","Sanjay Dutt", "Shah Rukh Khan", "Tiger Shroff", "Varun Dhawan",]
],
[
r"(.*) dialogue",
["Mere paas maa hai.","Pushpa, I hate tears…","Kitne aadmi the!","Babumoshai, zindagi badi honi chahiye, lambi nahi.","Rishtey mein toh hum tumhare baap lagte hai, naam hai Shahenshaah!","Dosti ka ek usool hai madam – no sorry, no thank you.","Mogambo khush hua!","Hum jahan khade hote hain line yahi se shuru hoti hai.","Bade bade deshon mein aisi choti-choti baatein hoti rehti hai, Senorita.","Haar kar jeetne wale ko baazigar kehte hai.","Mere Karan Arjun aayenge.","Agar maa ka doodh piya hai toh samne aa!","Uska to na bad luck hi kharab hai.","Crime Master Gogo naam hai mera, aankhen nikal ke gotiyan khelta hun main.","Tareekh pe tareekh, tareekh pe tareekh, tareekh pe tareekh milti gayi My Lord, par insaaf nahi mila","Rahul, naam toh suna hi hoga.","Mein apni favourite hoon!","Picture abhi baaki hai mere dost!","How’s the josh?","Thappad se darr nahi lagta sahab, pyaar se lagta hai.","Filmein sirf teen cheezo ke wajah se chalti hai…entertainment, entertainment, entertainment…aur main entertainment hoon.","All izz well",]
],
[
r"quit",
["Bye take care. See you soon :) ","It was nice talking to you. See you soon :)",]
],
[
r"(.*) joke",
["Why did the tomato blush? Because it saw the salad dressing.","What do you call bears with no ears? B","What do dentists call X-rays? Tooth pics.","Did you hear about the first restaurant to open on the moon? It had great food, but no atmosphere.","What did one wall say to the other wall? I’ll meet you at the corner.","When does a joke become a “dad” joke? When the punchline is apparent.","What did the paper say to the pencil? Write on!","How did the bullet lose its job? It got fired.","Why should you never trust stairs? They are always up to something.","Sometimes I tuck my knees into my chest and lean forward.That’s just how I roll.","What do you call a cheese that’s not yours? Nacho cheese!","Did you hear about the cheese factory that exploded in France?There was nothing left but de Brie.",]
],
[
r"even me",
["That's great"]
],
[
r"thank you",
["Your welcome , would you like to know something else if no then please type in QUIT to exit",]
],
]
def chat():
print("Hi! I am Y2K..")
chat = Chat(pairs, reflections)
chat.converse()

#initiate the conversation
if __name__ == "__main__":
chat()
1 change: 1 addition & 0 deletions Programs/P04_Factorial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Author: OMKAR PATHAK
#This program finds the favtorial of the specified numbers
#For example, factorial of 5 = 5*4*3*2*1 = 120

def factorial(number):
'''This function finds the factorial of the number passed as argument'''
Expand Down
29 changes: 29 additions & 0 deletions Programs/P19_SimpleStopWatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,32 @@
endtime = time.time()
print('Total Time:', round(endtime - starttime, 2),'secs')
break
# Press enter to start and stop the watch
"""
import time

print('Press Enter to begin, Press Enter again to stop')
if input()=='':
starttime = time.time()
print('Started')
while True:
val=input() #For ENTER
if val=='':
print('Stopped')
endtime = time.time()
print('Total Time:', round(endtime - starttime, 2),'secs')
break

"""

"""
Output:
Press Enter to begin, Press Enter again to stop

Started

Stopped
Total Time: 1.05 secs

"""

16 changes: 9 additions & 7 deletions Programs/P40_CipherText.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ def encrypt(message, key):
if chars in LETTERS:
num = LETTERS.find(chars)
num += key
encrypted += LETTERS[num]
else:
encrypted += symbol
if num>25:
num=num%25
num=num-1
encrypted =encrypted + LETTERS[num]

return encrypted

Expand All @@ -23,10 +24,11 @@ def decrypt(message, key):
for chars in message:
if chars in LETTERS:
num = LETTERS.find(chars)
num -= key
decrypted += LETTERS[num]
else:
decrypted += symbol
if num>25:
num=num%25
num=num-1
num = num -key
decrypted =decrypted+LETTERS[num]

return decrypted

Expand Down
23 changes: 22 additions & 1 deletion Programs/P43_BinarySearchTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ def postorder(self):
print(str(self.data), end = ' ')

class Tree(object):
def __init__(self):
def __init__(self, initial_data = []):
self.root = None

# If provided, add initial data
for data in initial_data:
self.insert(data)

def insert(self, data):
if self.root:
return self.root.insert(data)
Expand Down Expand Up @@ -106,6 +110,22 @@ def postorder(self):
print('Postorder: ')
self.root.postorder()


def pprint(self, head_node=0, _pre="", _last=True, term=False):

head_node = self.root if head_node == 0 else head_node

data = "*" if head_node is None else head_node.data

print(_pre, "`- " if _last else "|- ", data, sep="")
_pre += " " if _last else "| "

if term: return

for i, child in enumerate([head_node.leftChild, head_node.rightChild]):
self.pprint(child, _pre, bool(i) ,term=not(bool(child)))


if __name__ == '__main__':
tree = Tree()
tree.insert(10)
Expand All @@ -117,6 +137,7 @@ def postorder(self):
tree.insert(7)
tree.insert(15)
tree.insert(13)
tree.pprint()
print(tree.find(1))
print(tree.find(12))
tree.preorder()
Expand Down
2 changes: 1 addition & 1 deletion Programs/P56_Pangram.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def pangram(sentence):
# A short version of above function:
def pangram2(sentence):
alphabet = list(map(chr, range(97, 123)))
formattedString = ''.join(c for c in string if c.isalpha()).lower()
formattedString = ''.join(c for c in sentence if c.isalpha()).lower()
return set(alphabet) == set(formattedString)

if __name__ == '__main__':
Expand Down
Loading