From ffd031f8e3f65f65afe975791203cd1cf287de5b Mon Sep 17 00:00:00 2001 From: varun singh <58244695+varun-devops@users.noreply.github.com> Date: Fri, 2 Oct 2020 11:56:00 +0530 Subject: [PATCH 01/58] number guess game in python in this program you have to choose a number between 1-20 after enter number than, if your number matchs the right number than you win if not than try another number. thankyou. --- number guess game | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 number guess game diff --git a/number guess game b/number guess game new file mode 100644 index 0000000..3c5be3b --- /dev/null +++ b/number guess game @@ -0,0 +1,12 @@ +import random +r = random.randint(1,20) + +while(True): + inp = int(input()) + if(inpr): + print("oops,try a smaller number") + else: + print("congrats you choosed write number") + break; From 9075f3d5c423d399641dc369f298a65e81256d2d Mon Sep 17 00:00:00 2001 From: arunsharma00 <69965026+arunsharma00@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:53:50 +0530 Subject: [PATCH 02/58] Create Simple Calculator --- Simple Calculator | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Simple Calculator diff --git a/Simple Calculator b/Simple Calculator new file mode 100644 index 0000000..8aed082 --- /dev/null +++ b/Simple Calculator @@ -0,0 +1,48 @@ +# Program make a simple calculator + +# This function adds two numbers +def add(x, y): + return x + y + +# This function subtracts two numbers +def subtract(x, y): + return x - y + +# This function multiplies two numbers +def multiply(x, y): + return x * y + +# This function divides two numbers +def divide(x, y): + return x / y + + +print("Select operation.") +print("1.Add") +print("2.Subtract") +print("3.Multiply") +print("4.Divide") + +while True: + # Take input from the user + choice = input("Enter choice(1/2/3/4): ") + + # Check if choice is one of the four options + if choice in ('1', '2', '3', '4'): + num1 = float(input("Enter first number: ")) + num2 = float(input("Enter second number: ")) + + if choice == '1': + print(num1, "+", num2, "=", add(num1, num2)) + + elif choice == '2': + print(num1, "-", num2, "=", subtract(num1, num2)) + + elif choice == '3': + print(num1, "*", num2, "=", multiply(num1, num2)) + + elif choice == '4': + print(num1, "/", num2, "=", divide(num1, num2)) + break + else: + print("Invalid Input") From bca3c2e20765ac71625db9429c1bd5b650f08589 Mon Sep 17 00:00:00 2001 From: Alok Tiwari Date: Fri, 2 Oct 2020 13:28:21 +0530 Subject: [PATCH 03/58] Prime number Program to check if a number is prime or not --- prime number | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 prime number diff --git a/prime number b/prime number new file mode 100644 index 0000000..801324b --- /dev/null +++ b/prime number @@ -0,0 +1,22 @@ +# Program to check if a number is prime or not + +num = 407 + +# To take input from the user +#num = int(input("Enter a number: ")) + +# prime numbers are greater than 1 +if num > 1: + # check for factors + for i in range(2,num): + if (num % i) == 0: + print(num,"is not a prime number") + print(i,"times",num//i,"is",num) + break + else: + print(num,"is a prime number") + +# if input number is less than +# or equal to 1, it is not prime +else: + print(num,"is not a prime number") From 0b03f26d86f09ccca5860b9b5c4818ab79648d31 Mon Sep 17 00:00:00 2001 From: lalit19 <38009481+lalit19@users.noreply.github.com> Date: Fri, 2 Oct 2020 13:38:26 +0530 Subject: [PATCH 04/58] Create AreaTriangle program to find the area of triangle --- AreaTriangle | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 AreaTriangle diff --git a/AreaTriangle b/AreaTriangle new file mode 100644 index 0000000..0b080d6 --- /dev/null +++ b/AreaTriangle @@ -0,0 +1,10 @@ +a = float(input('Enter first side: ')) +b = float(input('Enter second side: ')) +c = float(input('Enter third side: ')) + +# calculate the semi-perimeter +s = (a + b + c) / 2 + +# calculate the area +area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 +print('The area of the triangle is %0.2f' %area) From 48085338815c9ce7eec020244f6106b887b9e146 Mon Sep 17 00:00:00 2001 From: rajanitnavapara8 <72249503+rajanitnavapara8@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:00:50 +0530 Subject: [PATCH 05/58] send sms using twilio --- twilio_sms.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 twilio_sms.py diff --git a/twilio_sms.py b/twilio_sms.py new file mode 100644 index 0000000..417c9b2 --- /dev/null +++ b/twilio_sms.py @@ -0,0 +1,13 @@ +from twilio.rest import Client + +sid = #write here sid number +token = #write token number here +client = Client(sid,token) + +my_msg = "Hi, It's Working correctly...☺" + +client.messages.create( + to= #type here number to whom you're sending , + from_= #type your number , + body=my_msg + ) From 444b6810d3606affdb1bc2138d6c1418c2f45c7d Mon Sep 17 00:00:00 2001 From: Qaiser Abbas Date: Fri, 2 Oct 2020 13:49:31 +0500 Subject: [PATCH 06/58] Define a split_in_two function that accepts a list and a number. --- split.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 split.py diff --git a/split.py b/split.py new file mode 100644 index 0000000..7d32271 --- /dev/null +++ b/split.py @@ -0,0 +1,5 @@ +def split_in_two(elements, num): + if num%2 == 0: + return elements[2:] + else: + return elements[:2] From c7b1998e9910293ea7dea93ff782af274b0e57b4 Mon Sep 17 00:00:00 2001 From: Sunit <64261771+suny55@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:51:51 +0530 Subject: [PATCH 07/58] Greater Number Python program to print the greatest of two numbers using the built-in function --- Greater Number | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Greater Number diff --git a/Greater Number b/Greater Number new file mode 100644 index 0000000..e77c480 --- /dev/null +++ b/Greater Number @@ -0,0 +1,5 @@ +# Python program to find the greatest of two numbers using the built-in function + +num1 = int(input("Enter the first number: ")) +num2 = int(input("Enter the second number: ")) +print(max(num1, num2), "is greater") From bd503c6562601c88b587a4c0b94176ba24cbc524 Mon Sep 17 00:00:00 2001 From: fahad-25082001 <72209033+fahad-25082001@users.noreply.github.com> Date: Fri, 2 Oct 2020 15:47:51 +0530 Subject: [PATCH 08/58] Snake water gun game Game by python programming as a beginnins of coding --- Snake water gun game | 76 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Snake water gun game diff --git a/Snake water gun game b/Snake water gun game new file mode 100644 index 0000000..d499df5 --- /dev/null +++ b/Snake water gun game @@ -0,0 +1,76 @@ +# SNAKE WATER GUN GAME + +import random +lst=['s','w','g'] +chance=10 +no_of_chance=0 +human_points =0 +computer_points=0 +print("\t \t \t \t SNAKE, WATER , GUN GAME \t \t \t \t") +print("s for sanke ") +print("w for water") +print("g for gun") +while no_of_chancehuman_points: + print("computer wins and human loose") +else: + print(" human wins and computer loose") + +print(f"human point is {human_points}and computer point is {computer_points}") From 4dfc9d9ef241897d5060a82fdb3ed969c01a8168 Mon Sep 17 00:00:00 2001 From: Tanmoy Gupta <64883575+Im-Tanmoy@users.noreply.github.com> Date: Fri, 2 Oct 2020 15:55:20 +0530 Subject: [PATCH 09/58] Convert Video to audio Run this code and extract any audio as a mp3 file from a video. --- Convert Video to audio | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Convert Video to audio diff --git a/Convert Video to audio b/Convert Video to audio new file mode 100644 index 0000000..a49ffae --- /dev/null +++ b/Convert Video to audio @@ -0,0 +1,5 @@ +import moviepy.editor as mp #[at first install moviepy in ur system] + +clip = mp.VideoFileClip(r'C:\\Users\\ADMIN\\Desktop\\Despacito.mp4') #[copy and paste the path where u saved ur video] + +clip.audio.write_audiofile('C:\\Users\\ADMIN\\Desktop\\Despacito_cvrt.mp3') #[give the path where u want to save ur audio file] From 43f5839c2bc1916722d16f0e25c5f026b6e3c7aa Mon Sep 17 00:00:00 2001 From: Vikas <72224550+Vikas09718@users.noreply.github.com> Date: Fri, 2 Oct 2020 16:19:47 +0530 Subject: [PATCH 10/58] Python3 program to find compound --- Python3 program to find compound | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Python3 program to find compound diff --git a/Python3 program to find compound b/Python3 program to find compound new file mode 100644 index 0000000..03f088d --- /dev/null +++ b/Python3 program to find compound @@ -0,0 +1,12 @@ +# Python3 program to find compound +# interest for given values. + +def compound_interest(principle, rate, time): + + # Calculates compound interest + Amount = principle * (pow((1 + rate / 100), time)) + CI = Amount - principle + print("Compound interest is", CI) + +# Driver Code +compound_interest(10000, 10.25, 5) From d43724db3669e8864730cf474b949ca29d365c65 Mon Sep 17 00:00:00 2001 From: Devipriya <36542167+cadwellh5@users.noreply.github.com> Date: Fri, 2 Oct 2020 17:20:07 +0530 Subject: [PATCH 11/58] Maximum sum of increasing subsequence if input is {1, 101, 2, 3, 100, 4, 5}, then output should be 106 (1 + 2 + 3 + 100), if the input array is {3, 4, 5, 10}, then output should be 22 (3 + 4 + 5 + 10) if the input array is {10, 5, 4, 3}, then output should be 10 --- MaxSumOfIncreasinSubsequence | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 MaxSumOfIncreasinSubsequence diff --git a/MaxSumOfIncreasinSubsequence b/MaxSumOfIncreasinSubsequence new file mode 100644 index 0000000..a7cf714 --- /dev/null +++ b/MaxSumOfIncreasinSubsequence @@ -0,0 +1,16 @@ +ts=int(input()) +l3=[] +l1=[] +for j in range (ts): + n=int(input()) + l3.clear() + li=list(map(int, input().split())) + for i in range(1,n): + t=li[i-1] + for j in range(0,i): + if(li[i]>li[j]): + t=t+li[j] + l3.append(t) + if(len(l3)!=0): + print (max(l3)) + li.clear() From 0865efdc463d749685b1421c3baf2e4fbb993e25 Mon Sep 17 00:00:00 2001 From: Naveen Kumar Chitturi <55271508+Naveen963@users.noreply.github.com> Date: Fri, 2 Oct 2020 18:21:54 +0530 Subject: [PATCH 12/58] DFS in python --- DFS | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 DFS diff --git a/DFS b/DFS new file mode 100644 index 0000000..9dffd21 --- /dev/null +++ b/DFS @@ -0,0 +1,89 @@ +# Python program to print DFS traversal for complete graph + +from collections import defaultdict + + +# This class represents a directed graph using adjacency +# list representation + +class Graph: + + + + # Constructor + + def __init__(self): + + + + # default dictionary to store graph + + self.graph = defaultdict(list) + + + + # function to add an edge to graph + + def addEdge(self,u,v): + + self.graph[u].append(v) + + + + # A function used by DFS + + def DFSUtil(self, v, visited): + + + + # Mark the current node as visited and print it + + visited[v]= True + + print v, + + + + # Recur for all the vertices adjacent to + + # this vertex + + for i in self.graph[v]: + + if visited[i] == False: + + self.DFSUtil(i, visited) + + + + + + # The function to do DFS traversal. It uses + + # recursive DFSUtil() + + def DFS(self): + + V = len(self.graph) #total vertices + + + + # Mark all the vertices as not visited + + visited =[False]*(V) + + + + # Call the recursive helper function to print + + # DFS traversal starting from all vertices one + + # by one + + for i in range(V): + + if visited[i] == False: + + self.DFSUtil(i, visited) + + From 2791ad6bd2d13edb467b985637b58dd4405d6df0 Mon Sep 17 00:00:00 2001 From: SHARIQ78692 <72261692+SHARIQ78692@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:30:25 +0530 Subject: [PATCH 13/58] pythonprime a program to check prime in python. --- pythonprime | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 pythonprime diff --git a/pythonprime b/pythonprime new file mode 100644 index 0000000..801324b --- /dev/null +++ b/pythonprime @@ -0,0 +1,22 @@ +# Program to check if a number is prime or not + +num = 407 + +# To take input from the user +#num = int(input("Enter a number: ")) + +# prime numbers are greater than 1 +if num > 1: + # check for factors + for i in range(2,num): + if (num % i) == 0: + print(num,"is not a prime number") + print(i,"times",num//i,"is",num) + break + else: + print(num,"is a prime number") + +# if input number is less than +# or equal to 1, it is not prime +else: + print(num,"is not a prime number") From 597dfb83834aa59c60e92d687a068a7153eaa780 Mon Sep 17 00:00:00 2001 From: Mohit5700 <72152449+Mohit5700@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:33:15 +0530 Subject: [PATCH 14/58] Python Program for factorial of a number Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. For example factorial of 6 is 6*5*4*3*2*1 which is 720. --- factorial | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 factorial diff --git a/factorial b/factorial new file mode 100644 index 0000000..5aaf12c --- /dev/null +++ b/factorial @@ -0,0 +1,16 @@ +def factorial(n): + if n < 0: + return 0 + elif n == 0 or n == 1: + return 1 + else: + fact = 1 + while(n > 1): + fact *= n + n -= 1 + return fact + +# Driver Code +num = 5; +print("Factorial of",num,"is", +factorial(num)) From 3f0a2cf1b7ff7829be171d7c6f42f6cbe4b56205 Mon Sep 17 00:00:00 2001 From: kirankumarsk <57290570+kirankumarsk@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:39:43 +0530 Subject: [PATCH 15/58] Create funny weight converter program to funny weight converter --- funny weight converter | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 funny weight converter diff --git a/funny weight converter b/funny weight converter new file mode 100644 index 0000000..58b32b2 --- /dev/null +++ b/funny weight converter @@ -0,0 +1,20 @@ +print('sup,user') +boi = input('what is your name name boi: ') +print("i guessed it, " + boi) +print(boi + " ,here v r going to convert your weight into pounds(lbs) from kilograms") +kgs = input("your weight in kgs: ") +kga = int(kgs) * 0.49 +kg = 'get some more weight kid, eat pizzas. u r 🤣🤣🤣' +kgb ='oh, workout football belly man. u r🤣🤣🤣🤣 ' + +if kga>50: + print(kg) +else: + print(kgb) + +print(kga) +print("pounds(lbs)") + +print("avoid the language😅, look code") +print("please give me star , i am just 14 trying coding") +print("to give a 🌟, tap the 3 dots and find star section and just tap on it please👍👍🤝") From e547bc4e4a3fcc85cb0ebf1f6f3abe4c00ed9aeb Mon Sep 17 00:00:00 2001 From: Mohammad umar mochi <65342404+maahieummah@users.noreply.github.com> Date: Fri, 2 Oct 2020 20:09:50 +0530 Subject: [PATCH 16/58] Create pythonevenodd --- pythonevenodd | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 pythonevenodd diff --git a/pythonevenodd b/pythonevenodd new file mode 100644 index 0000000..23efece --- /dev/null +++ b/pythonevenodd @@ -0,0 +1,5 @@ +num = int(input("Enter a number: ")) +if (num % 2) == 0: + print("{0} is Even number".format(num)) +else: + print("{0} is Odd number".format(num)) From 1bdeb4938f5c1dc1ab5fd6ab29344245e7387751 Mon Sep 17 00:00:00 2001 From: abhiray310 <64996064+abhiray310@users.noreply.github.com> Date: Fri, 2 Oct 2020 20:26:38 +0530 Subject: [PATCH 17/58] BMI CULCLATER PLEASE FRIEND SEE CODE AND ENJOY BMI CALCULATER. --- BMI CALCULATER | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 BMI CALCULATER diff --git a/BMI CALCULATER b/BMI CALCULATER new file mode 100644 index 0000000..cf44e69 --- /dev/null +++ b/BMI CALCULATER @@ -0,0 +1,31 @@ +filter_none +edit +play_arrow + +brightness_4 +#Python program to illustrate +# how to calculate BMI +def BMI(height, weight): + bmi = weight/(height**2) + return bmi + +# Driver code +height = 1.79832 +weight = 70 + +# calling the BMI function +bmi = BMI(height, weight) +print("The BMI is", format(bmi), "so ", end='') + +# Conditions to find out BMI category +if (bmi < 18.5): + print("underweight") + +elif ( bmi >= 18.5 and bmi < 24.9): + print("Healthy") + +elif ( bmi >= 24.9 and bmi < 30): + print("overweight") + +elif ( bmi >=30): + print("Suffering from Obesity") From 7e01c9b4f42f65cc42dde2beab1710ca3a25d448 Mon Sep 17 00:00:00 2001 From: Mohammad umar mochi <65342404+maahieummah@users.noreply.github.com> Date: Fri, 2 Oct 2020 20:40:46 +0530 Subject: [PATCH 18/58] Create forloopinpython --- forloopinpython | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 forloopinpython diff --git a/forloopinpython b/forloopinpython new file mode 100644 index 0000000..fa90667 --- /dev/null +++ b/forloopinpython @@ -0,0 +1,5 @@ +fruits = ["apple", "banana", "cherry"] +for x in fruits: + if x == "banana": + break + print(x) From 216bfb6b9a5b49421c958762eeb557303ccd9e8d Mon Sep 17 00:00:00 2001 From: mrlazyProgrammer <72256784+mrlazyProgrammer@users.noreply.github.com> Date: Fri, 2 Oct 2020 21:05:25 +0530 Subject: [PATCH 19/58] Python Program to Find the Factorial of a Number In this article, you'll learn to find the factorial of a number and display it. --- Factorial of a Number | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Factorial of a Number diff --git a/Factorial of a Number b/Factorial of a Number new file mode 100644 index 0000000..60d09f1 --- /dev/null +++ b/Factorial of a Number @@ -0,0 +1,19 @@ +# Python program to find the factorial of a number provided by the user. + +# change the value for a different result +num = 7 + +# To take input from the user +#num = int(input("Enter a number: ")) + +factorial = 1 + +# check if the number is negative, positive or zero +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +elif num == 0: + print("The factorial of 0 is 1") +else: + for i in range(1,num + 1): + factorial = factorial*i + print("The factorial of",num,"is",factorial) From 6112d9b6ff7a0789f15abd8da2b4ca26757af6ef Mon Sep 17 00:00:00 2001 From: vedang6575 <72148375+vedang6575@users.noreply.github.com> Date: Fri, 2 Oct 2020 22:15:54 +0530 Subject: [PATCH 20/58] class BasicLexer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thus we will need some basic tokens such as NAME, NUMBER, STRING. In any programming language, there will be space between two characters. Thus we create an ignore literal. Then we also create the basic literals like ‘=’, ‘+’ etc., NAME tokens are basically names of variables, which can be defined by the regular expression [a-zA-Z_][a-zA-Z0-9_]*. STRING tokens are string values and are bounded by quotation marks(” “). This can be defined by the regular expression \”.*?\” --- class BasicLexer with python programming | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 class BasicLexer with python programming diff --git a/class BasicLexer with python programming b/class BasicLexer with python programming new file mode 100644 index 0000000..c991436 --- /dev/null +++ b/class BasicLexer with python programming @@ -0,0 +1,28 @@ + tokens = { NAME, NUMBER, STRING } + ignore = '\t ' + literals = { '=', '+', '-', '/', + '*', '(', ')', ',', ';'} + + + # Define tokens as regular expressions + # (stored as raw strings) + NAME = r'[a-zA-Z_][a-zA-Z0-9_]*' + STRING = r'\".*?\"' + + # Number token + @_(r'\d+') + def NUMBER(self, t): + + # convert it into a python integer + t.value = int(t.value) return t + + # Comment token + @_(r'//.*') + def COMMENT(self, t): + pass + + # Newline token(used only for showing + # errors in new line) + @_(r'\n+') + def newline(self, t): + self.lineno = t.value.count('\n') From 8aee6be5d390a597ef2bee107e77d7766dd3ef13 Mon Sep 17 00:00:00 2001 From: vedang6575 <72148375+vedang6575@users.noreply.github.com> Date: Fri, 2 Oct 2020 22:21:46 +0530 Subject: [PATCH 21/58] update Python Program to Convert Celsius To Fahrenheit and Vice Versa In the following program, we are taking the input from the user, a user enters the temperature in Celsius and the program converts the entered value into Fahrenheit using the conversion formula we have seen above. --- Python program to convert Celsius to Fahrenheit | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Python program to convert Celsius to Fahrenheit b/Python program to convert Celsius to Fahrenheit index 5c5071b..0b28093 100644 --- a/Python program to convert Celsius to Fahrenheit +++ b/Python program to convert Celsius to Fahrenheit @@ -1,9 +1,3 @@ -celsius = float(input('Enter temperature in Celsius: ')) - - - - - -fahrenheit = (celsius * 1.8) + 32 - -print('%0.1f Celsius is equal to %0.1f degree Fahrenheit'%(celsius,fahrenheit)) +fahrenheit = float(input("Enter temperature in fahrenheit: ")) +celsius = (fahrenheit - 32) * 5/9 +print('%.2f Fahrenheit is: %0.2f Celsius' %(fahrenheit, celsius)) From ea9b6a906a0d56d71777a1eb2e1d9132ee075f3b Mon Sep 17 00:00:00 2001 From: DhanrajDesai <48202923+DhanrajDesai@users.noreply.github.com> Date: Fri, 2 Oct 2020 22:29:20 +0530 Subject: [PATCH 22/58] Fibonacci number How to check if a given number is Fibonacci number --- Fibonacci number | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Fibonacci number diff --git a/Fibonacci number b/Fibonacci number new file mode 100644 index 0000000..5db83fe --- /dev/null +++ b/Fibonacci number @@ -0,0 +1,17 @@ + +import math +def isPerfectSquare(x): + s = int(math.sqrt(x)) + return s*s == x + + +def isFibonacci(n): + + return isPerfectSquare(5*n*n + 4) or isPerfectSquare(5*n*n - 4) + + +for i in range(1,11): + if (isFibonacci(i) == True): + print i,"is a Fibonacci Number" + else: + print i,"is a not Fibonacci Number " From 5b22a7ffae07b49efbfe497f7b114e2da45216d0 Mon Sep 17 00:00:00 2001 From: Mehak Agrawal Date: Fri, 2 Oct 2020 22:56:50 +0530 Subject: [PATCH 23/58] PDF to Audiobook converter Python code to convert pdf into an audiobook --- audiobook | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 audiobook diff --git a/audiobook b/audiobook new file mode 100644 index 0000000..df1107e --- /dev/null +++ b/audiobook @@ -0,0 +1,12 @@ +import pyttsx3 +import PyPDF2 +book = open('book.pdf','rb') +pdfReader = PyPDF2.PdfFileReader(book) +number_of_pages = pdfReader.numPages +print(number_of_pages) +speaker = pyttsx3.init() +for num in range(1, number_of_pages): + page_number = pdfReader.getPage(10) + text = page_number.extractText() + speaker.say(text) + speaker.runAndWait() From cd288cc53634697f2a0e8e25e1004be82d5010c9 Mon Sep 17 00:00:00 2001 From: sumit120398 <72256303+sumit120398@users.noreply.github.com> Date: Sat, 3 Oct 2020 00:34:34 +0530 Subject: [PATCH 24/58] Calculator Python Program to Make a Simple Calculator --- Python Program to Make a Simple Calculator | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Python Program to Make a Simple Calculator diff --git a/Python Program to Make a Simple Calculator b/Python Program to Make a Simple Calculator new file mode 100644 index 0000000..72ac9c2 --- /dev/null +++ b/Python Program to Make a Simple Calculator @@ -0,0 +1,71 @@ +def add(x, y): + + """This function adds two numbers"" + + return x + y + +def subtract(x, y): + + """This function subtracts two numbers""" + + return x - y + +def multiply(x, y): + + """This function multiplies two numbers""" + + return x * y + +def divide(x, y): + + """This function divides two numbers""" + + return x / y + + + +print("Select operation.") + +print("1.Add") + +print("2.Subtract") + +print("3.Multiply") + +print("4.Divide") + + + +choice = input("Enter choice(1/2/3/4):") + + + +num1 = int(input("Enter first number: ")) + +num2 = int(input("Enter second number: ")) + + + +if choice == '1': + + print(num1,"+",num2,"=", add(num1,num2)) + + + +elif choice == '2': + + print(num1,"-",num2,"=", subtract(num1,num2)) + + + +elif choice == '3': + + print(num1,"*",num2,"=", multiply(num1,num2)) + +elif choice == '4': + + print(num1,"/",num2,"=", divide(num1,num2)) + +else: + + print("Invalid input") From a5f809cf4fcaa140806dd3158576b93cb323089d Mon Sep 17 00:00:00 2001 From: Fazalahmad44 <71704478+Fazalahmad44@users.noreply.github.com> Date: Sat, 3 Oct 2020 02:33:20 +0530 Subject: [PATCH 25/58] Tic-Tac-Toe --- Tic-Tac-Toe | 249 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 Tic-Tac-Toe diff --git a/Tic-Tac-Toe b/Tic-Tac-Toe new file mode 100644 index 0000000..e4a8ae5 --- /dev/null +++ b/Tic-Tac-Toe @@ -0,0 +1,249 @@ +def Welcome(): + print(' *Welcome to tic-tac-toe game*') + #dont take sleep more than 2 seconds then user will get bored + sleep(1) + print() + print('Computer will decide who will play first') + print() + #for Hint Feature In Computer AI i have passed Player letter instead of computer letter + print('If you need Hint in the middle of game \npress any of this [Hint,hint,H,h]') + sleep(1) + print() + print(''' *** Format of Game ** + | | 1 | 2 | 3 + - - - - - - - - - - - - + | | 4 | 5 | 6 + - - - - - - - - - - - - + | | 7 | 8 | 9 + ''') + + +#Fuction to draw Board +#you can modify this sleep method if you dont need it +def DrawBoard(board,NeedSleep=True): + #I thought for hint u dont need sleep method so i given default value for Needsleep + if NeedSleep: + sleep(1) + print() + print(' '+board[1]+' | '+board[2]+' | '+board[3]) + print(' - - - - - - - ') + print(' '+board[4]+' | '+board[5]+' | '+board[6]) + print(' - - - - - - - ') + print(' '+board[7]+' | '+board[8]+' | '+board[9]) + print() + +#asking the player to choose thier Letter (X or O) +def InputPlayerLetter(): + letter='' + #Ask untill user enters x or o + while not(letter == 'X' or letter == 'O'): + print('Do you want to be X or O') + letter = input().upper() + + #returning list bcz of later use + if letter == 'X': + return ['X','O'] + if letter == 'O': + return ['O','X'] + +#Deciding who should play first randomly +#in usual tic-tac-toe games player first,but it selects randomly between computer and player +def WhoFirst(): + opponents = ['computer','player'] + if choice(opponents) == 'computer': + return 'computer' + else : + return 'player' + +#this function asks player to play again +def PlayAgain(): + print() + print('Do you want to Play Again (y or n)') + playagain = input().lower().startswith('y') + return playagain + +#function for making move +def MakeMove(board,letter,move): + board[move] = letter + +#check if any one win,returns True if wins +#In tic-tac-toe there are 8 possibilities of winning +#horizontal => 3 | vertical => 3 | diagonal => 2 +def IsWinner(board,letter): + return ( (board[7] == letter and board[8] == letter and board[9] == letter ) or + (board[4] == letter and board[5] == letter and board[6] == letter ) or + (board[1] == letter and board[2] == letter and board[3] == letter ) or + (board[1] == letter and board[4] == letter and board[7] == letter ) or + (board[2] == letter and board[5] == letter and board[8] == letter ) or + (board[3] == letter and board[6] == letter and board[9] == letter ) or + (board[1] == letter and board[5] == letter and board[9] == letter ) or + (board[3] == letter and board[5] == letter and board[7] == letter ) ) + +#duplicate board is useful when we wanted to make temporary changes to the temporary copy of the board without changing the original board +def GetBoardCopy(board): + DupeBoard = [] + for i in board: + DupeBoard.append(i) + return DupeBoard + +#fuction to check is space is free +def IsSpaceFree(board,move): + return board[move] == ' ' + +#Getting the player move +def GetPlayerMove(board): + move = '' + + while move not in '1 2 3 4 5 6 7 8 9'.split() or not IsSpaceFree(board,int(move)): + print() + print('Enter your move (1 - 9)') + move = input() + #if player wants Hint + if move in HintInput: + return move + break + return int(move) + +#choose random move from given list +#it is used when AI wants to choose out of many possibilities +def ChooseRandomFromList(board,MoveList): + PossibleMoves = [] + for i in MoveList: + if IsSpaceFree(board,i): + PossibleMoves.append(i) + if len(PossibleMoves) != 0: + return choice(PossibleMoves) + else: + return None + +#creating computers AI +#this ai works on this algorithm +#1.it checks if computer can win in next move,else +#2.it checks if player can win in next move,then it blocks it,else +#3.it chooses any available spaces from the corner[1,3,7,9],else +#4.it fills middle square if space free,else +#5.it chooses any available spaces from sides,ie,[2,4,6,8] +#if you interchange the 3 and 4 steps the AI becomes little Hard,ie,it fills middle then corner +#-------------------------------------- +#Get computer move +def GetComputerMove(board,ComputerLetter): + if ComputerLetter == 'X': + PlayerLetter = 'O' + else: + PlayerLetter = 'X' + + #1.check computer can win in next move + for i in range(1,10): + copy = GetBoardCopy(board) + if IsSpaceFree(copy,i): + MakeMove(copy,ComputerLetter,i) + if IsWinner(copy,ComputerLetter): + return i + + + #2.check player can win in next move + for i in range(1,10): + copy = GetBoardCopy(board) + if IsSpaceFree(copy,i): + MakeMove(copy,PlayerLetter,i) + if IsWinner(copy,PlayerLetter): + return i + + #3.checking for corner + move = ChooseRandomFromList(board,[1,3,7,9]) + if move != None: + return move + + #4.checking for the center + if IsSpaceFree(board,5): + return 5 + + #5.checking for sides + return ChooseRandomFromList(board,[2,4,6,8]) + +#--------------------------------------- + +#checking board is full or not +def IsBoardFull(board): + for i in range(1,10): + if IsSpaceFree(board,i): + return False + return True + +#fuction to print the final win or tie board +#made this to separate usual board and winning or tie board +def FinalBoard(board,NeedSleep=True): + print(' |-------------|') + DrawBoard(board,NeedSleep) + print(' |-------------|') + + +#LETS START THE GAME +Welcome() +while True: + #intialising board + TheBoard = [' '] * 10 + PlayerLetter,ComputerLetter = InputPlayerLetter() + turn = WhoFirst() + print(f'The {turn} will go first') + + #gameloop + Playing = True + while Playing: + + if turn == 'player': + print(f" Turn => {turn}") + HintInput = ['Hint','hint','H','h'] + #taking players input + move = GetPlayerMove(TheBoard) + #if player needs Hint + while move in HintInput: + #following code gives hint to the user + #it runs player letter to computer AI + HintBox = [] + for i in TheBoard: + HintBox.append(i) + hint = GetComputerMove(HintBox,PlayerLetter) + MakeMove(HintBox,PlayerLetter,hint) + print(f'HINT : placing at {hint} is better') + FinalBoard(HintBox,False) + move = GetPlayerMove(TheBoard) + + MakeMove(TheBoard,PlayerLetter,move) + + + if IsWinner(TheBoard,PlayerLetter): + FinalBoard(TheBoard) + print('❤You have WON the game❤') + Playing = not Playing + elif IsBoardFull(TheBoard): + FinalBoard(TheBoard) + print('The game is TIE\nIts good to PLAY untill you WIN❤') + Playing = not Playing + else : + DrawBoard(TheBoard) + turn = 'computer' + + else : + #computer move + print(f" Turn => {turn}") + move = GetComputerMove(TheBoard,ComputerLetter) + MakeMove(TheBoard,ComputerLetter,move) + + + if IsWinner(TheBoard,ComputerLetter): + FinalBoard(TheBoard) + print('❤Try again bro you will win❤') + Playing = not Playing + elif IsBoardFull(TheBoard): + FinalBoard(TheBoard) + print('The game is TIE\nIts good to PLAY untill you WIN❤') + Playing = not Playing + else : + DrawBoard(TheBoard) + turn = 'player' + + if not PlayAgain(): + print("***❤GIVE STAR ONLY IF YOU LIKE❤***") + break + From 6f9fb982c348e9cb2f412fc9e4f6e53fa2014cea Mon Sep 17 00:00:00 2001 From: ant19997x <72279868+ant19997x@users.noreply.github.com> Date: Fri, 2 Oct 2020 19:08:44 -0700 Subject: [PATCH 26/58] Quadratic Formula Takes the values of a,b,c, and calculates the two solutions for the quadratic equation ax^2 + bx + c = - --- Quadratic formula | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Quadratic formula diff --git a/Quadratic formula b/Quadratic formula new file mode 100644 index 0000000..a0b20fd --- /dev/null +++ b/Quadratic formula @@ -0,0 +1,11 @@ +import cmath + +print('Solve the quadratic equation: ax**2 + bx + c = 0') +a = float(input('Please enter a : ')) +b = float(input('Please enter b : ')) +c = float(input('Please enter c : ')) +delta = (b**2) - (4*a*c) +solution1 = (-b-cmath.sqrt(delta))/(2*a) +solution2 = (-b+cmath.sqrt(delta))/(2*a) + +print('The solutions are {0} and {1}'.format(solution1,solution2)) From 0adb443e9054b8765af9e1e311236b8b6bc6bfdc Mon Sep 17 00:00:00 2001 From: Saurabh Swaraj <64193088+Saurabhswaraj920@users.noreply.github.com> Date: Sat, 3 Oct 2020 09:04:48 +0530 Subject: [PATCH 27/58] solveQuadraticEq Python code to solve any quadratic equation which inputs are given by the user --- solveQuadraticEq | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solveQuadraticEq diff --git a/solveQuadraticEq b/solveQuadraticEq new file mode 100644 index 0000000..6e372d5 --- /dev/null +++ b/solveQuadraticEq @@ -0,0 +1,18 @@ +# Solve the quadratic equation ax**2 + bx + c = 0 + +# import complex math module +import cmath + +a = 1 +b = 5 +c = 6 + +# calculate the discriminant +d = (b**2) - (4*a*c) + +# find two solutions irrespective of the nature of roots +sol1 = (-b-cmath.sqrt(d))/(2*a) +sol2 = (-b+cmath.sqrt(d))/(2*a) + +# printing the solution of quatratic equation +print('The solution are {0} and {1}'.format(sol1,sol2)) From 23a92c60eee7732589578316c4e9978e2eab4231 Mon Sep 17 00:00:00 2001 From: Gaurav6342 <48625801+Gaurav6342@users.noreply.github.com> Date: Sat, 3 Oct 2020 10:14:34 +0530 Subject: [PATCH 28/58] calender.py this python code can show the number of datys in year from 2010 to 2020 --- calender | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 calender diff --git a/calender b/calender new file mode 100644 index 0000000..231807b --- /dev/null +++ b/calender @@ -0,0 +1,44 @@ +def is_leap_year(year): + return (year % 4 == 0) and (year % 100 != 0) or (year % 400 == 0) + +def numberOfDaysInAYear(year) : + if year == 2010 and output.is_leap_year = True: + print (365) + elif year==2011 : + print(365) + elif year==2012 : + print (366) + elif year==2013 : + print(365) + elif year==2014 : + print(365) + elif year==2015 : + print(365) + elif year==2016 : + print (366) + elif year==2017 : + print(365) + elif year==2018 : + print(365) + elif year==2019 : + print(365) + elif year == 2020 : + print (366) + + else: print('') + + + + print ( year == 2010 ,"Days are 365") + print ( year == 2011 ,"Days are 365") + print ( year == 2012 ,"Days are 366") + print ( year == 2013 ,"Days are 365") + print ( year == 2014 ,"Days are 365") + print ( year == 2015 ,"Days are 365") + print ( year == 2016 ,"Days are 366") + print ( year == 2017 ,"Days are 365") + print ( year == 2018 ,"Days are 365") + print ( year == 2019 ,"Days are 365") + print ( year == 2020 ,"Days are 366") + + From b53c6d866d737708b2b1028b34e589279bcb3f4a Mon Sep 17 00:00:00 2001 From: Vipin Singh <60010447+VipinSingh9680@users.noreply.github.com> Date: Sat, 3 Oct 2020 11:20:41 +0530 Subject: [PATCH 29/58] calculator program to made calculator using tkinter --- calculator | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 calculator diff --git a/calculator b/calculator new file mode 100644 index 0000000..a786591 --- /dev/null +++ b/calculator @@ -0,0 +1,148 @@ + +from tkinter import * +expression = "" +def press(num): + + global expression + expression = expression + str(num) + + # update the expression by using set method + equation.set(expression) + + +# Function to evaluate the final expression +def equalpress(): + + try: + + global expression + + # eval function evaluate the expression + # and str function convert the result + # into string + total = str(eval(expression)) + + equation.set(total) + + # initialze the expression variable + # by empty string + expression = "" + + # if error is generate then handle + # by the except block + except: + + equation.set(" error ") + expression = "" + + +# Function to clear the contents +# of text entry box +def clear(): + global expression + expression = "" + equation.set("") + + +# Driver code +if __name__ == "__main__": + # create a GUI window + gui = Tk() + + # set the background colour of GUI window + gui.configure(background="light green") + + # set the title of GUI window + gui.title("Simple Calculator") + + # set the configuration of GUI window + gui.geometry("270x150") + + # StringVar() is the variable class + # we create an instance of this class + equation = StringVar() + + # create the text entry box for + # showing the expression . + expression_field = Entry(gui, textvariable=equation) + + # grid method is used for placing + # the widgets at respective positions + # in table like structure . + expression_field.grid(columnspan=4, ipadx=70) + + equation.set('enter your expression') + + # create a Buttons and place at a particular + # location inside the root window . + # when user press the button, the command or + # function affiliated to that button is executed . + button1 = Button(gui, text=' 1 ', fg='black', bg='red', + command=lambda: press(1), height=1, width=7) + button1.grid(row=2, column=0) + + button2 = Button(gui, text=' 2 ', fg='black', bg='red', + command=lambda: press(2), height=1, width=7) + button2.grid(row=2, column=1) + + button3 = Button(gui, text=' 3 ', fg='black', bg='red', + command=lambda: press(3), height=1, width=7) + button3.grid(row=2, column=2) + + button4 = Button(gui, text=' 4 ', fg='black', bg='red', + command=lambda: press(4), height=1, width=7) + button4.grid(row=3, column=0) + + button5 = Button(gui, text=' 5 ', fg='black', bg='red', + command=lambda: press(5), height=1, width=7) + button5.grid(row=3, column=1) + + button6 = Button(gui, text=' 6 ', fg='black', bg='red', + command=lambda: press(6), height=1, width=7) + button6.grid(row=3, column=2) + + button7 = Button(gui, text=' 7 ', fg='black', bg='red', + command=lambda: press(7), height=1, width=7) + button7.grid(row=4, column=0) + + button8 = Button(gui, text=' 8 ', fg='black', bg='red', + command=lambda: press(8), height=1, width=7) + button8.grid(row=4, column=1) + + button9 = Button(gui, text=' 9 ', fg='black', bg='red', + command=lambda: press(9), height=1, width=7) + button9.grid(row=4, column=2) + + button0 = Button(gui, text=' 0 ', fg='black', bg='red', + command=lambda: press(0), height=1, width=7) + button0.grid(row=5, column=0) + + plus = Button(gui, text=' + ', fg='black', bg='red', + command=lambda: press("+"), height=1, width=7) + plus.grid(row=2, column=3) + + minus = Button(gui, text=' - ', fg='black', bg='red', + command=lambda: press("-"), height=1, width=7) + minus.grid(row=3, column=3) + + multiply = Button(gui, text=' * ', fg='black', bg='red', + command=lambda: press("*"), height=1, width=7) + multiply.grid(row=4, column=3) + + divide = Button(gui, text=' / ', fg='black', bg='red', + command=lambda: press("/"), height=1, width=7) + divide.grid(row=5, column=3) + + equal = Button(gui, text=' = ', fg='black', bg='red', + command=equalpress, height=1, width=7) + equal.grid(row=5, column=2) + + clear = Button(gui, text='Clear', fg='black', bg='red', + command=clear, height=1, width=7) + clear.grid(row=5, column='1') + + Decimal= Button(gui, text='.', fg='black', bg='red', + command=lambda: press('.'), height=1, width=7) + Decimal.grid(row=6, column=0) + # start the GUI + gui.mainloop() From b1607fb4fc7af8efb10ba1bca2b6742ad6d133f1 Mon Sep 17 00:00:00 2001 From: sakshamsinghal011 <72293082+sakshamsinghal011@users.noreply.github.com> Date: Sat, 3 Oct 2020 11:36:01 +0530 Subject: [PATCH 30/58] check leap year program to find the leap year --- leap year | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 leap year diff --git a/leap year b/leap year new file mode 100644 index 0000000..ba983bc --- /dev/null +++ b/leap year @@ -0,0 +1,18 @@ +def checkYear(year): + if (year % 4) == 0: + if (year % 100) == 0: + if (year % 400) == 0: + return True + else: + return False + else: + return True + else: + return False + +# Driver Code +year = 2000 +if(checkYear(year)): + print("Leap Year") +else: + print("Not a Leap Year") From 8d2b5d7b530bf4f2d8a0834386449c0b10fbb3ce Mon Sep 17 00:00:00 2001 From: NILADRI BIT Date: Sat, 3 Oct 2020 11:54:19 +0530 Subject: [PATCH 31/58] fibonacci Python Program to Print the Fibonacci sequence --- fibonacci.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 fibonacci.py diff --git a/fibonacci.py b/fibonacci.py new file mode 100644 index 0000000..9f6b1b3 --- /dev/null +++ b/fibonacci.py @@ -0,0 +1,23 @@ +# Program to display the Fibonacci sequence up to n-th term + +nterms = int(input("How many terms? ")) + +# first two terms +n1, n2 = 0, 1 +count = 0 + +# check if the number of terms is valid +if nterms <= 0: + print("Please enter a positive integer") +elif nterms == 1: + print("Fibonacci sequence upto",nterms,":") + print(n1) +else: + print("Fibonacci sequence:") + while count < nterms: + print(n1) + nth = n1 + n2 + # update values + n1 = n2 + n2 = nth + count += 1 From 6f7f401f7e32840f8f955e075a177c31b77755fa Mon Sep 17 00:00:00 2001 From: ANAND SAURAV <72293098+anandsaurav07@users.noreply.github.com> Date: Sat, 3 Oct 2020 12:02:19 +0530 Subject: [PATCH 32/58] Linear Search linear search using python. --- Linear Search | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Linear Search diff --git a/Linear Search b/Linear Search new file mode 100644 index 0000000..412fdcf --- /dev/null +++ b/Linear Search @@ -0,0 +1,18 @@ +def linear_search(alist, key): + """Return index of key in alist. Return -1 if key not present.""" + for i in range(len(alist)): + if alist[i] == key: + return i + return -1 + + +alist = input('Enter the list of numbers: ') +alist = alist.split() +alist = [int(x) for x in alist] +key = int(input('The number to search for: ')) + +index = linear_search(alist, key) +if index < 0: + print('{} was not found.'.format(key)) +else: + print('{} was found at index {}.'.format(key, index)) From 8c91586d8376e9d82a153e98d1e12a53822dfb5e Mon Sep 17 00:00:00 2001 From: Debarati678 <72296024+Debarati678@users.noreply.github.com> Date: Sat, 3 Oct 2020 13:47:40 +0530 Subject: [PATCH 33/58] Guess a no in 9 trials Take trials(maximum 9 times) to find the no. You will get hint to put a lesser or a greater no after each trial. You will also get the trial numbers left. If you exceed 9 trials, "game over" will be printed. --- Guess the no | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Guess the no diff --git a/Guess the no b/Guess the no new file mode 100644 index 0000000..da00477 --- /dev/null +++ b/Guess the no @@ -0,0 +1,17 @@ +n=20 +number_of_guesses=1 +print("Number of guesses is limited to 9 times: ") +while (number_of_guesses<=9): + guess_number=int(input("Guess the no :\n")) + if guess_number<20: + print("please input greater no:\n") + elif guess_number>20: + print("please enter less no:\n") + else: + print("you won\n") + print (number_of_gueeses, "number of guesses he took to finish.") + break + print(9-number_of_guesses, "number of guesses left") + number_of_guesses = number_of_guesses + 1 +if(number_of_guesses>9): + print("Game Over") From ed64a78e1af37750792f5841fb87b128a932d67a Mon Sep 17 00:00:00 2001 From: Aakashtiwari007 Date: Sat, 3 Oct 2020 13:53:15 +0530 Subject: [PATCH 34/58] Matrix Multiplication using Nested Loop --- Matrix Multiplication using Nested Loop.py | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Matrix Multiplication using Nested Loop.py diff --git a/Matrix Multiplication using Nested Loop.py b/Matrix Multiplication using Nested Loop.py new file mode 100644 index 0000000..4078137 --- /dev/null +++ b/Matrix Multiplication using Nested Loop.py @@ -0,0 +1,25 @@ +# Program to multiply two matrices using nested loops + +# 3x3 matrix +X = [[12,7,3], + [4 ,5,6], + [7 ,8,9]] +# 3x4 matrix +Y = [[5,8,1,2], + [6,7,3,0], + [4,5,9,1]] +# result is 3x4 +result = [[0,0,0,0], + [0,0,0,0], + [0,0,0,0]] + +# iterate through rows of X +for i in range(len(X)): + # iterate through columns of Y + for j in range(len(Y[0])): + # iterate through rows of Y + for k in range(len(Y)): + result[i][j] += X[i][k] * Y[k][j] + +for r in result: + print(r) From 9db42957ee14333d4772e871f6bfe8fce1014d1f Mon Sep 17 00:00:00 2001 From: Aakashtiwari007 Date: Sat, 3 Oct 2020 13:54:56 +0530 Subject: [PATCH 35/58] SortWordsinAlphabeticOrder --- Sort Words in Alphabetic Order.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Sort Words in Alphabetic Order.py diff --git a/Sort Words in Alphabetic Order.py b/Sort Words in Alphabetic Order.py new file mode 100644 index 0000000..f4ebe04 --- /dev/null +++ b/Sort Words in Alphabetic Order.py @@ -0,0 +1,18 @@ +# Program to sort alphabetically the words form a string provided by the user + +my_str = "Hello this Is an Example With cased letters" + +# To take input from the user +#my_str = input("Enter a string: ") + +# breakdown the string into a list of words +words = my_str.split() + +# sort the list +words.sort() + +# display the sorted words + +print("The sorted words are:") +for word in words: + print(word) From 34febf9e0fc403b14de1c5cf12b6eeabae861fa4 Mon Sep 17 00:00:00 2001 From: pratikson <70327865+pratikson@users.noreply.github.com> Date: Sat, 3 Oct 2020 14:04:20 +0530 Subject: [PATCH 36/58] Factorial!no Find Factorial of any number --- Factorial! | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Factorial! diff --git a/Factorial! b/Factorial! new file mode 100644 index 0000000..90e13f0 --- /dev/null +++ b/Factorial! @@ -0,0 +1,19 @@ + Python program to find the factorial of a number provided by the user. + +# change the value for a different result +num = 7 + +# To take input from the user +#num = int(input("Enter a number: ")) + +factorial = 1 + +# check if the number is negative, positive or zero +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +elif num == 0: + print("The factorial of 0 is 1") +else: + for i in range(1,num + 1): + factorial = factorial*i + print("The factorial of",num,"is",factorial) From 4284f648d47a1ad985de940735533270e1056ed4 Mon Sep 17 00:00:00 2001 From: Shanu899 <72297366+Shanu899@users.noreply.github.com> Date: Sat, 3 Oct 2020 14:51:29 +0530 Subject: [PATCH 37/58] Decision making of car driving User will put any number of age. Program will tell if you are eligible or not to drive a car or not. --- Car driving | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Car driving diff --git a/Car driving b/Car driving new file mode 100644 index 0000000..9c05c92 --- /dev/null +++ b/Car driving @@ -0,0 +1,9 @@ +var1=18 +var2=int(input("Enter Your Age: ")) +if var2>var1: + print("drive") +elif var2==var1: + print("decide") + +else: + print ("do not drive") From 5de973adb3ced00ba7979567546ddfb718f72b17 Mon Sep 17 00:00:00 2001 From: MartianCoder-git <72254243+MartianCoder-git@users.noreply.github.com> Date: Sat, 3 Oct 2020 14:52:36 +0530 Subject: [PATCH 38/58] KNN_algorithm Attempted to write KNN algorithm using python and built a flower classifier model. I have commented the lines involving classifier code from the in-built scikit-learn library. --- KNN_algorithm | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 KNN_algorithm diff --git a/KNN_algorithm b/KNN_algorithm new file mode 100644 index 0000000..e05bebd --- /dev/null +++ b/KNN_algorithm @@ -0,0 +1,65 @@ +from sklearn import datasets +from sklearn.model_selection import train_test_split +from sklearn.neighbors import KNeighborsClassifier +from sklearn.metrics import accuracy_score +from scipy.spatial import distance + +def euc(a,b): + return distance.euclidean(a, b) + + +class ScrappyKNN(): + def fit(self, features_train, labels_train): + self.features_train = features_train + self.labels_train = labels_train + + def predict(self, features_test): + predictions = [] + for item in features_test: + label = self.closest(item) + predictions.append(label) + + return predictions + + def closest(self, item): + best_dist = euc(item, self.features_train[0]) + best_index = 0 + for i in range(1,len(self.features_train)): + dist = euc(item, self.features_train[i]) + if dist < best_dist: + best_dist = dist + best_index = i + return self.labels_train[best_index] + +iris = datasets.load_iris() + +print(iris) + +features = iris.data +labels = iris.target + +print(features) +print(labels) + +features_train, features_test, labels_train, labels_test = train_test_split(features, labels, test_size=.5) +#print(len(features)) +#print(len(features_train)) + +my_classifier = ScrappyKNN() +#my_classifier = KNeighborsClassifier() +my_classifier.fit(features_train, labels_train) + +prediction = my_classifier.predict(features_test) + +print(prediction) +print(accuracy_score(labels_test, prediction)) + +iris1 = [[7.1, 2.9, 5.3, 2.4]] #virginica +iris_prediction = my_classifier.predict(iris1) + +if iris_prediction == 0: + print("Setosa") +if iris_prediction == 1: + print("Versicolor") +if iris_prediction == 2: + print("Virginica") From c667242fc517a81bf17162e1fd9ce1d7920d2312 Mon Sep 17 00:00:00 2001 From: Shanu899 <72297366+Shanu899@users.noreply.github.com> Date: Sat, 3 Oct 2020 14:56:09 +0530 Subject: [PATCH 39/58] Dictionary Use Use will take name of the persons included in dictionary. Program will show the items under them. --- Use of dictionary | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Use of dictionary diff --git a/Use of dictionary b/Use of dictionary new file mode 100644 index 0000000..497584c --- /dev/null +++ b/Use of dictionary @@ -0,0 +1,5 @@ +d1={"Shyam":"Honey", "Imli":"Lichi", "Raj":"Mango", "Marie": "Coco"} +print(d1) +a=input("Enter the Word:") +b=a.capitalize() +print(b,"=",d1[b]) From 44cd2d98bae85958067376777ee8ac7c49ea33d9 Mon Sep 17 00:00:00 2001 From: Shanu899 <72297366+Shanu899@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:06:08 +0530 Subject: [PATCH 40/58] Number comparison User will give two numbers. Program will decide which one is greater. --- Comparison | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Comparison diff --git a/Comparison b/Comparison new file mode 100644 index 0000000..30f693a --- /dev/null +++ b/Comparison @@ -0,0 +1,6 @@ +a = int(input("enter a\n")) +b = int(input("enter b\n")) +if b < a: + print("a is greater than b") +else: + print("b is greater than a") From 7ed81206027a665c1c33f268ad78e2748fe9a9dc Mon Sep 17 00:00:00 2001 From: ShrutiPandey27 <69622082+ShrutiPandey27@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:37:16 +0530 Subject: [PATCH 41/58] Create tic_tac_toe.py Here I have created tic tac toe game in a very easy manner using easy language python --- tic_tac_toe.py | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tic_tac_toe.py diff --git a/tic_tac_toe.py b/tic_tac_toe.py new file mode 100644 index 0000000..9239669 --- /dev/null +++ b/tic_tac_toe.py @@ -0,0 +1,90 @@ +import os +import time + +board = [' ',' ',' ',' ',' ',' ',' ',' ',' ',' '] +player = 1 + +########win Flags########## +Win = 1 +Draw = -1 +Running = 0 +Stop = 1 +########################### +Game = Running +Mark = 'X' + +#This Function Draws Game Board +def DrawBoard(): + print(" %c | %c | %c " % (board[1],board[2],board[3])) + print("___|___|___") + print(" %c | %c | %c " % (board[4],board[5],board[6])) + print("___|___|___") + print(" %c | %c | %c " % (board[7],board[8],board[9])) + print(" | | ") + +#This Function Checks position is empty or not +def CheckPosition(x): + if(board[x] == ' '): + return True + else: + return False + +#This Function Checks player has won or not +def CheckWin(): + global Game + #Horizontal winning condition + if(board[1] == board[2] and board[2] == board[3] and board[1] != ' '): + Game = Win + elif(board[4] == board[5] and board[5] == board[6] and board[4] != ' '): + Game = Win + elif(board[7] == board[8] and board[8] == board[9] and board[7] != ' '): + Game = Win + #Vertical Winning Condition + elif(board[1] == board[4] and board[4] == board[7] and board[1] != ' '): + Game = Win + elif(board[2] == board[5] and board[5] == board[8] and board[2] != ' '): + Game = Win + elif(board[3] == board[6] and board[6] == board[9] and board[3] != ' '): + Game=Win + #Diagonal Winning Condition + elif(board[1] == board[5] and board[5] == board[9] and board[5] != ' '): + Game = Win + elif(board[3] == board[5] and board[5] == board[7] and board[5] != ' '): + Game=Win + #Match Tie or Draw Condition + elif(board[1]!=' ' and board[2]!=' ' and board[3]!=' ' and board[4]!=' ' and board[5]!=' ' and board[6]!=' ' and board[7]!=' ' and board[8]!=' ' and board[9]!=' '): + Game=Draw + else: + Game=Running + +print("Tic-Tac-Toe Game Designed By Sourabh Somani") +print("Player 1 [X] --- Player 2 [O]\n") +print() +print() +print("Please Wait...") +time.sleep(3) +while(Game == Running): + os.system('cls') + DrawBoard() + if(player % 2 != 0): + print("Player 1's chance") + Mark = 'X' + else: + print("Player 2's chance") + Mark = 'O' + choice = int(input("Enter the position between [1-9] where you want to mark : ")) + if(CheckPosition(choice)): + board[choice] = Mark + player+=1 + CheckWin() + +os.system('cls') +DrawBoard() +if(Game==Draw): + print("Game Draw") +elif(Game==Win): + player-=1 + if(player%2!=0): + print("Player 1 Won") + else: + print("Player 2 Won") From c4716fb770efdf4c3fc360c85c16b4856dbe8612 Mon Sep 17 00:00:00 2001 From: DEEPAK KUMAR SAHOO <56642683+kumardeepak123@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:49:57 +0530 Subject: [PATCH 42/58] dfs traversal --- dfsTraversal | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 dfsTraversal diff --git a/dfsTraversal b/dfsTraversal new file mode 100644 index 0000000..51dddad --- /dev/null +++ b/dfsTraversal @@ -0,0 +1,51 @@ + +from collections import defaultdict + +class Graph: + + + def __init__(self): + + + self.graph = defaultdict(list) + + + def addEdge(self, u, v): + self.graph[u].append(v) + + + def DFSUtil(self, v, visited): + + + visited[v] = True + print(v, end = ' ') + + + for i in self.graph[v]: + if visited[i] == False: + self.DFSUtil(i, visited) + + + def DFS(self, v): + + + visited = [False] * (max(self.graph)+1) + + + self.DFSUtil(v, visited) + + + +# Create a graph given + +g = Graph() +g.addEdge(0, 1) +g.addEdge(0, 2) +g.addEdge(1, 2) +g.addEdge(2, 0) +g.addEdge(2, 3) +g.addEdge(3, 3) + +print("Following is DFS from (starting from vertex 2)") +g.DFS(2) + From 9301520759eba28f144244b95178f706e2181aa0 Mon Sep 17 00:00:00 2001 From: yakshsoni <62012450+yakshsoni@users.noreply.github.com> Date: Sat, 3 Oct 2020 15:59:05 +0530 Subject: [PATCH 43/58] Cloning or Copying a list Cloning or Copying a list --- Cloning or Copying a list | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Cloning or Copying a list diff --git a/Cloning or Copying a list b/Cloning or Copying a list new file mode 100644 index 0000000..8e0e324 --- /dev/null +++ b/Cloning or Copying a list @@ -0,0 +1,11 @@ +# Python code to clone or copy a list +# Using the in-built function list() +def Cloning(li1): + li_copy = list(li1) + return li_copy + +# Driver Code +li1 = [4, 8, 2, 10, 15, 18] +li2 = Cloning(li1) +print("Original List:", li1) +print("After Cloning:", li2) From 42a928cf7290dd9b6ee24bd5e924f079bf31a4ea Mon Sep 17 00:00:00 2001 From: amiyagiri <72298965+amiyagiri@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:13:04 +0530 Subject: [PATCH 44/58] oddeven to check whether a given number is odd or even. --- oddeven | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 oddeven diff --git a/oddeven b/oddeven new file mode 100644 index 0000000..0a382f0 --- /dev/null +++ b/oddeven @@ -0,0 +1,7 @@ +print("hello world") +num = int(input("Enter a number: ")) +mod = num % 2 +if mod > 0: + print("This is an odd number.") +else: + print("This is an even number.") From 1167d1170408fca3b7ed151e212e4129f3b4eb45 Mon Sep 17 00:00:00 2001 From: abhishekkushwah827 <63289147+abhishekkushwah827@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:41:41 +0530 Subject: [PATCH 45/58] Create Matrix Multiplication in Python #python #metrices --- Matrix Multiplication in Python | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Matrix Multiplication in Python diff --git a/Matrix Multiplication in Python b/Matrix Multiplication in Python new file mode 100644 index 0000000..0011a17 --- /dev/null +++ b/Matrix Multiplication in Python @@ -0,0 +1,28 @@ +def matrix_multiplication(M,N): + + R = [[0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0]] + + for i in range(0, 4): + for j in range(0, 4): + for k in range(0, 4): + R[i][j] += M[i][k] * N[k][j] + + for i in range(0,4): + for j in range(0,4): + print(R[i][j],end=" ") + print("\n",end="") + +M = [[1, 1, 1, 1], + [2, 2, 2, 2], + [3, 3, 3, 3], + [4, 4, 4, 4]] + +N = [[1, 1, 1, 1], + [2, 2, 2, 2], + [3, 3, 3, 3], + [4, 4, 4, 4]] + +matrix_multiplication(M,N) From 706ad56fa5dae08feaea6e26b8a2813aaaa692ef Mon Sep 17 00:00:00 2001 From: baibhavtripathy <68537807+baibhavtripathy@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:42:49 +0530 Subject: [PATCH 46/58] Pacman Hacktoberfest 2020 --- Pacman | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 Pacman diff --git a/Pacman b/Pacman new file mode 100644 index 0000000..6d98922 --- /dev/null +++ b/Pacman @@ -0,0 +1,159 @@ +from random import choice +from turtle import * +from freegames import floor, vector + +state = {'score': 0} +path = Turtle(visible=False) +writer = Turtle(visible=False) +aim = vector(5, 0) +pacman = vector(-40, -80) +ghosts = [ + [vector(-180, 160), vector(5, 0)], + [vector(-180, -160), vector(0, 5)], + [vector(100, 160), vector(0, -5)], + [vector(100, -160), vector(-5, 0)], +] +tiles = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, + 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, + 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, + 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, + 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, + 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, + 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +] + +def square(x, y): + "Draw square using path at (x, y)." + path.up() + path.goto(x, y) + path.down() + path.begin_fill() + + for count in range(4): + path.forward(20) + path.left(90) + + path.end_fill() + +def offset(point): + "Return offset of point in tiles." + x = (floor(point.x, 20) + 200) / 20 + y = (180 - floor(point.y, 20)) / 20 + index = int(x + y * 20) + return index + +def valid(point): + "Return True if point is valid in tiles." + index = offset(point) + + if tiles[index] == 0: + return False + + index = offset(point + 19) + + if tiles[index] == 0: + return False + + return point.x % 20 == 0 or point.y % 20 == 0 + +def world(): + "Draw world using path." + bgcolor('black') + path.color('blue') + + for index in range(len(tiles)): + tile = tiles[index] + + if tile > 0: + x = (index % 20) * 20 - 200 + y = 180 - (index // 20) * 20 + square(x, y) + + if tile == 1: + path.up() + path.goto(x + 10, y + 10) + path.dot(2, 'white') + +def move(): + "Move pacman and all ghosts." + writer.undo() + writer.write(state['score']) + + clear() + + if valid(pacman + aim): + pacman.move(aim) + + index = offset(pacman) + + if tiles[index] == 1: + tiles[index] = 2 + state['score'] += 1 + x = (index % 20) * 20 - 200 + y = 180 - (index // 20) * 20 + square(x, y) + + up() + goto(pacman.x + 10, pacman.y + 10) + dot(20, 'yellow') + + for point, course in ghosts: + if valid(point + course): + point.move(course) + else: + options = [ + vector(5, 0), + vector(-5, 0), + vector(0, 5), + vector(0, -5), + ] + plan = choice(options) + course.x = plan.x + course.y = plan.y + + up() + goto(point.x + 10, point.y + 10) + dot(20, 'red') + + update() + + for point, course in ghosts: + if abs(pacman - point) < 20: + return + + ontimer(move, 100) + +def change(x, y): + "Change pacman aim if valid." + if valid(pacman + vector(x, y)): + aim.x = x + aim.y = y + +setup(420, 420, 370, 0) +hideturtle() +tracer(False) +writer.goto(160, 160) +writer.color('white') +writer.write(state['score']) +listen() +onkey(lambda: change(5, 0), 'Right') +onkey(lambda: change(-5, 0), 'Left') +onkey(lambda: change(0, 5), 'Up') +onkey(lambda: change(0, -5), 'Down') +world() +move() +done() From 57bc2b4ea8d080e853c2392e0c855e1493b99b3e Mon Sep 17 00:00:00 2001 From: baibhavtripathy <68537807+baibhavtripathy@users.noreply.github.com> Date: Sat, 3 Oct 2020 16:43:58 +0530 Subject: [PATCH 47/58] Snake Hacktoberfest 2020 --- Snake | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Snake diff --git a/Snake b/Snake new file mode 100644 index 0000000..241bff6 --- /dev/null +++ b/Snake @@ -0,0 +1,70 @@ +pip install pygame + +import pygame +import time +pygame.init() + +white = (255, 255, 255) +black = (0, 0, 0) +red = (255, 0, 0) + +dis_width = 800 +dis_height = 600 +dis = pygame.display.set_mode((dis_width, dis_width)) +pygame.display.set_caption('Snake Game by Baibhav') + +game_over = False + +x1 = dis_width/2 +y1 = dis_height/2 + +snake_block=10 + +x1_change = 0 +y1_change = 0 + +clock = pygame.time.Clock() +snake_speed=30 + +font_style = pygame.font.SysFont(None, 50) + +def message(msg,color): + mesg = font_style.render(msg, True, color) + dis.blit(mesg, [dis_width/2, dis_height/2]) + +while not game_over: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + game_over = True + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + x1_change = -snake_block + y1_change = 0 + elif event.key == pygame.K_RIGHT: + x1_change = snake_block + y1_change = 0 + elif event.key == pygame.K_UP: + y1_change = -snake_block + x1_change = 0 + elif event.key == pygame.K_DOWN: + y1_change = snake_block + x1_change = 0 + + if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0: + game_over = True + + x1 += x1_change + y1 += y1_change + dis.fill(white) + pygame.draw.rect(dis, black, [x1, y1, snake_block, snake_block]) + + pygame.display.update() + + clock.tick(snake_speed) + +message("You lost",red) +pygame.display.update() +time.sleep(2) + +pygame.quit() +quit() From aab9dc5b448498ff1cedafb3944561050a28db76 Mon Sep 17 00:00:00 2001 From: Sushil Gupta Date: Sat, 3 Oct 2020 16:54:33 +0530 Subject: [PATCH 48/58] Adding solution for Repeated Substring Pattern problem --- Repeated_Substring_Pattern.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Repeated_Substring_Pattern.py diff --git a/Repeated_Substring_Pattern.py b/Repeated_Substring_Pattern.py new file mode 100644 index 0000000..4855729 --- /dev/null +++ b/Repeated_Substring_Pattern.py @@ -0,0 +1,18 @@ +class Solution: + def repeatedSubstringPattern(self, s: str) -> bool: + cal = run = 0 + tem = s[:cal] + for i in range(len(s)): + cal += 1 + tem = s[:cal] + + # Jump is with the size of searching elelment i.e cal + for j in range(cal, len(s), cal): + if tem == s[j: j + cal]: + run = j + cal + if run == len(s): + return True + else: + break + return False + From 29cc0014b34204bdec79be7320903252a515c8a7 Mon Sep 17 00:00:00 2001 From: pavanteja1999 <72302686+pavanteja1999@users.noreply.github.com> Date: Sat, 3 Oct 2020 17:17:19 +0530 Subject: [PATCH 49/58] Auto Wesite Visitor Python Script Visits Websites Automatically --- Auto Website Visitor | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Auto Website Visitor diff --git a/Auto Website Visitor b/Auto Website Visitor new file mode 100644 index 0000000..b04643d --- /dev/null +++ b/Auto Website Visitor @@ -0,0 +1,62 @@ +##--- Auto Website Visitor by khalsalabs ---- #### +import urllib2 +import random +import threading +import sys +import time +class Connect: + req = urllib2.Request('http://your-website-name.com') + con_sucess, con_failed, con_total=0,0,0 + url_total, proxy_total= 0,0 + url_list =[] + proxy_list= [] + agent_list =[] + +def __init__(self): + pF = open('proxy.txt','r') + pR = pF.read() + self.proxy_list = pR.split('n') + + uF = open('url.txt','r') + uR = uF.read() + self.url_list = uR.split('n') + + aF = open('agent.txt','r') + aR = aF.read() + self.agent_list = aR.split('n') + +def prep_con(self): + rURL = random.randint(0,(len(self.url_list))-1) + self.req = urllib2.Request(self.url_list[rURL]) + rAGENT = random.randint(0,(len(self.agent_list))-1) + self.req.add_header('User-agent',self.agent_list[rAGENT]) + +def make_con(self): + count, time_stamp =0,0 + for proxy in self.proxy_list: + self.req.set_proxy(proxy,'http') + if count%4==0: + if self.con_total < 2*count: + time_stamp = 6 + else: + time_stamp = 3 + threading.Thread(target=self.visitURL).start() + time.sleep(time_stamp) + count += 1 + +def visit(self): + try: + f = urllib2.urlopen(self.req) + self.con_sucess += 1 + except: + self.con_failed += 1 + self.con_total += 1 + print self.con_total,"total connections, success = ",self.con_sucess," failed= ",self.con_failed + +def visitURL(self): + self.prep_con() + self.visit() + +if __name__ == "__main__": + cnct = Connect() + cnct.make_con() From 62110c0e41c89c7244f7a6b3bc11d1b284df4920 Mon Sep 17 00:00:00 2001 From: Bipul-coder <72294442+Bipul-coder@users.noreply.github.com> Date: Sat, 3 Oct 2020 17:34:53 +0530 Subject: [PATCH 50/58] Calculate simple Interest WAP to Calculate Simple Interest(SI),Read the principle, rate of interest and number of years from the user. --- ..., rate of interest and number of years from the user. | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 WAP to Calculate Simple Interest(SI),Read the principle, rate of interest and number of years from the user. diff --git a/WAP to Calculate Simple Interest(SI),Read the principle, rate of interest and number of years from the user. b/WAP to Calculate Simple Interest(SI),Read the principle, rate of interest and number of years from the user. new file mode 100644 index 0000000..abfb7fc --- /dev/null +++ b/WAP to Calculate Simple Interest(SI),Read the principle, rate of interest and number of years from the user. @@ -0,0 +1,8 @@ +principle = eval(input("Enter the principle")) +ROI = eval(input("Enter the ROI")) +Years = eval(input("Enter the years")) +print("Principle:-",principle) +print("ROI:-",ROI) +print("Years:-",Years) +SI = principle * ROI * Years/100 +print("The Simple interest of the number",SI) From 25c244ec1c6bfb82b2db2cde3fc93b268b83bb75 Mon Sep 17 00:00:00 2001 From: pavanteja1999 <72302686+pavanteja1999@users.noreply.github.com> Date: Sat, 3 Oct 2020 17:48:10 +0530 Subject: [PATCH 51/58] Crashing Car Game Car Games Using Python Pygame Module --- Car Game in Python | 110 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Car Game in Python diff --git a/Car Game in Python b/Car Game in Python new file mode 100644 index 0000000..fce0c34 --- /dev/null +++ b/Car Game in Python @@ -0,0 +1,110 @@ +import pygame +import time +import random + +pygame.init() + +display_width = 800 +display_height = 600 + +black = (0,0,0) +white = (255,255,255) +red = (255,0,0) + +car_width = 73 + +gameDisplay = pygame.display.set_mode((display_width,display_height)) +pygame.display.set_caption('A bit Racey') +clock = pygame.time.Clock() + +carImg = pygame.image.load('racecar.png') + +def things(thingx, thingy, thingw, thingh, color): + pygame.draw.rect(gameDisplay, color, [thingx, thingy, thingw, thingh]) + +def car(x,y): + gameDisplay.blit(carImg,(x,y)) + +def text_objects(text, font): + textSurface = font.render(text, True, black) + return textSurface, textSurface.get_rect() + +def message_display(text): + largeText = pygame.font.Font('freesansbold.ttf',115) + TextSurf, TextRect = text_objects(text, largeText) + TextRect.center = ((display_width/2),(display_height/2)) + gameDisplay.blit(TextSurf, TextRect) + + pygame.display.update() + + time.sleep(2) + + game_loop() + + + +def crash(): + message_display('You Crashed') + +def game_loop(): + x = (display_width * 0.45) + y = (display_height * 0.8) + + x_change = 0 + + thing_startx = random.randrange(0, display_width) + thing_starty = -600 + thing_speed = 7 + thing_width = 100 + thing_height = 100 + + gameExit = False + + while not gameExit: + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + quit() + + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + x_change = -5 + if event.key == pygame.K_RIGHT: + x_change = 5 + + if event.type == pygame.KEYUP: + if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT: + x_change = 0 + + x += x_change + gameDisplay.fill(white) + + # things(thingx, thingy, thingw, thingh, color) + things(thing_startx, thing_starty, thing_width, thing_height, black) + thing_starty += thing_speed + car(x,y) + + if x > display_width - car_width or x < 0: + crash() + + if thing_starty > display_height: + thing_starty = 0 - thing_height + thing_startx = random.randrange(0,display_width) + + #### + if y < thing_starty+thing_height: + print('y crossover') + + if x > thing_startx and x < thing_startx + thing_width or x+car_width > thing_startx and x + car_width < thing_startx+thing_width: + print('x crossover') + crash() + #### + + pygame.display.update() + clock.tick(60) + + +game_loop() +pygame.quit() +quit() From 6235a6b5fff1b4fbdfd4b3b7443caf99c332b5dc Mon Sep 17 00:00:00 2001 From: Ajay Saini <61726148+AjaySaini1999@users.noreply.github.com> Date: Sat, 3 Oct 2020 18:26:35 +0530 Subject: [PATCH 52/58] Matrix Multiplication using Nested Loop Matrix Multiplication --- Matrix Multiplication | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Matrix Multiplication diff --git a/Matrix Multiplication b/Matrix Multiplication new file mode 100644 index 0000000..d090d7f --- /dev/null +++ b/Matrix Multiplication @@ -0,0 +1,27 @@ +# Program to multiply two matrices using nested loops + +# 3x3 matrix +X = [[12,7,3], + [4 ,5,6], + [7 ,8,9]] +# 3x4 matrix +Y = [[5,8,1,2], + [6,7,3,0], + [4,5,9,1]] +# result is 3x4 +result = [[0,0,0,0], + [0,0,0,0], + [0,0,0,0]] + +# iterate through rows of X +for i in range(len(X)): + # iterate through columns of Y + for j in range(len(Y[0])): + # iterate through rows of Y + for k in range(len(Y)): + result[i][j] += X[i][k] * Y[k][j] + +for r in result: + print(r) + +######################################################## From 0df6b1df7ed1b57bf18cdc2f8dbce2fffe12a7bc Mon Sep 17 00:00:00 2001 From: saurabhsonawane2015 <66660505+saurabhsonawane2015@users.noreply.github.com> Date: Sat, 3 Oct 2020 18:28:45 +0530 Subject: [PATCH 53/58] Create Dayofprogrammer --- Dayofprogrammer | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Dayofprogrammer diff --git a/Dayofprogrammer b/Dayofprogrammer new file mode 100644 index 0000000..f981de6 --- /dev/null +++ b/Dayofprogrammer @@ -0,0 +1,47 @@ +#!/bin/python +import sys +y = int(raw_input().strip()) +# your code goes here +months = {0:31,1:28,2:31,3:30,4:31,5:30,6:31,7:31,8:30,9:31,10:30,11:31} +if y <= 1917: + tot = 0 + for i in range(12): + if tot + months[i] > 256: + break + if y % 4 == 0 and i == 1: + tot = tot + 29 + else: + tot = tot + months[i] + ans = "" + day = 256 - tot + month = i + 1 + ans = ans + str(day) + ".0" + str(month) + "." + str(y) + print ans +elif y == 1918: + tot = 0 + for i in range(12): + if tot + months[i] > 256: + break + if i == 1: + tot = tot + 15 + else: + tot = tot + months[i] + ans = "" + day = 256 - tot + month = i + 1 + ans = ans + str(day) + ".0" + str(month) + "." + str(y) + print ans +else: + tot = 0 + for i in range(12): + if tot + months[i] > 256: + break + if (y % 400 == 0 or (y % 4 == 0 and y % 100 != 0)) and i == 1: + tot = tot + 29 + else: + tot = tot + months[i] + ans = "" + day = 256 - tot + month = i + 1 + ans = ans + str(day) + ".0" + str(month) + "." + str(y) + print ans From 9f01007c7ec029cfe7b813bc43aa5bb90c6e977d Mon Sep 17 00:00:00 2001 From: Vanasetty Rohit Date: Sat, 3 Oct 2020 18:32:37 +0530 Subject: [PATCH 54/58] Create Knapsack_problem.py --- Knapsack_problem.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Knapsack_problem.py diff --git a/Knapsack_problem.py b/Knapsack_problem.py new file mode 100644 index 0000000..9d982c2 --- /dev/null +++ b/Knapsack_problem.py @@ -0,0 +1,27 @@ +# A Dynamic Programming based Python +# Program for 0-1 Knapsack problem +# Returns the maximum value that can +# be put in a knapsack of capacity W +def knapSack(W, wt, val, n): + K = [[0 for x in range(W + 1)] for x in range(n + 1)] + + # Build table K[][] in bottom up manner + for i in range(n + 1): + for w in range(W + 1): + if i == 0 or w == 0: + K[i][w] = 0 + elif wt[i-1] <= w: + K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]) + else: + K[i][w] = K[i-1][w] + + return K[n][W] + +# Driver program to test above function +val = [60, 100, 120] +wt = [10, 20, 30] +W = 50 +n = len(val) +print(knapSack(W, wt, val, n)) + +# This code is contributed by Vanasetty Rohit From 5a5314bea42f4c0ef319b2353eb0ca9f09bbb783 Mon Sep 17 00:00:00 2001 From: akshit bansal <72249011+akshit250@users.noreply.github.com> Date: Sat, 3 Oct 2020 19:22:08 +0530 Subject: [PATCH 55/58] Create addition using function --- addition using function | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 addition using function diff --git a/addition using function b/addition using function new file mode 100644 index 0000000..16a0e2d --- /dev/null +++ b/addition using function @@ -0,0 +1,9 @@ +#Python program to add two numbers using function + +def add_num(a,b):#function for addition + sum=a+b; + return sum; #return value + +num1=25 #variable declaration +num2=55 +print("The sum is",add_num(num1,num2))#call the function From cbc76e9e8c6ab6da18042280c726e18ec86f926d Mon Sep 17 00:00:00 2001 From: Darshan15071998 <43002535+Darshan15071998@users.noreply.github.com> Date: Sat, 3 Oct 2020 19:24:25 +0530 Subject: [PATCH 56/58] PrintHelloWorld.py Used for simply providing output in python as "Hello World !" --- PrintHelloWorld.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 PrintHelloWorld.py diff --git a/PrintHelloWorld.py b/PrintHelloWorld.py new file mode 100644 index 0000000..4363e40 --- /dev/null +++ b/PrintHelloWorld.py @@ -0,0 +1,2 @@ +#It's very simple to code in Python :) +print("Hello World !") From 610e4838fc0ac9c389389c1073c9be2a4d819399 Mon Sep 17 00:00:00 2001 From: Shibu-goswami <57540891+Shibu-goswami@users.noreply.github.com> Date: Sat, 3 Oct 2020 19:40:52 +0530 Subject: [PATCH 57/58] average number write a python program to find the average number in a list. --- avgno | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 avgno diff --git a/avgno b/avgno new file mode 100644 index 0000000..fd765c8 --- /dev/null +++ b/avgno @@ -0,0 +1,9 @@ +def cal_average(num): + sum_num = 0 + for t in num: + sum_num = sum_num + t + + avg = sum_num / len(num) + return avg + +print("The average is", cal_average([17,26,3,21,35])) From 075af4e0fe3c921a412cf3b4e0fdda76029e05ee Mon Sep 17 00:00:00 2001 From: amiyagiri <72298965+amiyagiri@users.noreply.github.com> Date: Sat, 3 Oct 2020 19:59:44 +0530 Subject: [PATCH 58/58] calculate simple interest A Python program to find simple interest for given principal amount, time and rate of interest. --- simple interest | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 simple interest diff --git a/simple interest b/simple interest new file mode 100644 index 0000000..0f130af --- /dev/null +++ b/simple interest @@ -0,0 +1,17 @@ +# Python3 program to find simple interest +# for given principal amount, time and +# rate of interest. + + +def simple_interest(p,t,r): + print('The principal is', p) + print('The time period is', t) + print('The rate of interest is',r) + + si = (p * t * r)/100 + + print('The Simple Interest is', si) + return si + +# Driver code +simple_interest(1000, 2, 5)