From 8d8c761fa218a84087ed757881f7887105b60c11 Mon Sep 17 00:00:00 2001 From: Shawn Date: Sun, 8 Oct 2017 15:57:18 +0800 Subject: [PATCH 01/17] Added program to find factorial of number #9 --- Code/factorial.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Code/factorial.py diff --git a/Code/factorial.py b/Code/factorial.py new file mode 100644 index 0000000..82c7aee --- /dev/null +++ b/Code/factorial.py @@ -0,0 +1,15 @@ +#program to find the factorial of a number provided by a user + +if __name__ == "__main__": + number = int(raw_input("Enter a number to get its factorial: ")) + factorial = 1 + + if number < 0: + print("Sorry, factorial doesn't exist for negative numbers!") + elif number == 0: + print("The factorial of 0 is 1") + else: + for i in range(1, number + 1): + factorial = factorial * i + print "The factorial of %r is %r" % (number, factorial) + \ No newline at end of file From 6bec965b064bd5f6b004c934fbaf74caa793f096 Mon Sep 17 00:00:00 2001 From: ashishkrishan1995 Date: Sun, 8 Oct 2017 14:33:05 +0530 Subject: [PATCH 02/17] bubblesort using python --- Code/bubbleSort.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Code/bubbleSort.py diff --git a/Code/bubbleSort.py b/Code/bubbleSort.py new file mode 100644 index 0000000..1382633 --- /dev/null +++ b/Code/bubbleSort.py @@ -0,0 +1,25 @@ +# Python program for implementation of Bubble Sort + +def bubbleSort(arr): + n = len(arr) + + # Traverse through all array elements + for i in range(n): + + # Last i elements are already in place + for j in range(0, n-i-1): + + # traverse the array from 0 to n-i-1 + # Swap if the element found is greater + # than the next element + if arr[j] > arr[j+1] : + arr[j], arr[j+1] = arr[j+1], arr[j] + +# Driver code to test above +arr = [64, 34, 25, 12, 22, 11, 90] + +bubbleSort(arr) + +print ("Sorted array is:") +for i in range(len(arr)): + print ("%d" %arr[i]), From 0a9d29af1786752ba3a031a3feb77fccfaee4bce Mon Sep 17 00:00:00 2001 From: 16BIT0127Prateek Date: Sun, 8 Oct 2017 23:31:11 +0530 Subject: [PATCH 03/17] Add Fibonacci.py --- Code/factorial.py | 30 +++++++++++++++--------------- Code/fibonacci.py | 9 +++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 Code/fibonacci.py diff --git a/Code/factorial.py b/Code/factorial.py index 86f427b..f0f7ef0 100644 --- a/Code/factorial.py +++ b/Code/factorial.py @@ -1,16 +1,16 @@ - -#program to find the factorial of a number provided by a user - -if __name__ == "__main__": - number = int(raw_input("Enter a number to get its factorial: ")) - factorial = 1 - - if number < 0: - print("Sorry, factorial doesn't exist for negative numbers!") - elif number == 0: - print("The factorial of 0 is 1") - else: - for i in range(1, number + 1): - factorial = factorial * i - print "The factorial of %r is %r" % (number, factorial) + +#program to find the factorial of a number provided by a user + +if __name__ == "__main__": + number = int(raw_input("Enter a number to get its factorial: ")) + factorial = 1 + + if number < 0: + print("Sorry, factorial doesn't exist for negative numbers!") + elif number == 0: + print("The factorial of 0 is 1") + else: + for i in range(1, number + 1): + factorial = factorial * i + print "The factorial of %r is %r" % (number, factorial) \ No newline at end of file diff --git a/Code/fibonacci.py b/Code/fibonacci.py new file mode 100644 index 0000000..3ae5624 --- /dev/null +++ b/Code/fibonacci.py @@ -0,0 +1,9 @@ +def fibonacci(n): + if(n <= 1): + return n + else: + return(fibonacci(n-1) + fibonacci(n-2)) +n = int(input("Enter number of terms:")) +print("Fibonacci sequence:") +for i in range(n): + print fibonacci(i), From c22df48261a036f61896dfe04fac43839e81bb27 Mon Sep 17 00:00:00 2001 From: 16BIT0127Prateek Date: Sun, 8 Oct 2017 23:37:28 +0530 Subject: [PATCH 04/17] Bug Resolved Fibonacci --- Code/fibonacci.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Code/fibonacci.py b/Code/fibonacci.py index 3ae5624..dbb8d91 100644 --- a/Code/fibonacci.py +++ b/Code/fibonacci.py @@ -6,4 +6,5 @@ def fibonacci(n): n = int(input("Enter number of terms:")) print("Fibonacci sequence:") for i in range(n): - print fibonacci(i), + print(fibonacci(i)) + From ac7b9df9869d1079c944fbece728257ffda59e2a Mon Sep 17 00:00:00 2001 From: Vasu Goel Date: Mon, 9 Oct 2017 00:15:21 +0530 Subject: [PATCH 05/17] Create HCF.py --- Code/HCF.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Code/HCF.py diff --git a/Code/HCF.py b/Code/HCF.py new file mode 100644 index 0000000..88b1834 --- /dev/null +++ b/Code/HCF.py @@ -0,0 +1,16 @@ +# Program to find HCF in python + +def hcf(x, y): # x and y are two integers you can input + # smaller will be used to store the variable for running the shorter loop + ans = 1 + if (x < y): + smaller = x + else: + smaller = y + for i in range(2, smaller+1): + if ((x%i == 0) and (y%i == 0)): + ans = i + return ans + +print(hcf(27, 6)) + From f0cd694d5fae3041b70e8ab1c8f7033f2b0f3010 Mon Sep 17 00:00:00 2001 From: naveentata Date: Sun, 8 Oct 2017 20:00:36 +0000 Subject: [PATCH 06/17] Python Code for BinarySearch --- Code/BinarySearch.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Code/BinarySearch.py diff --git a/Code/BinarySearch.py b/Code/BinarySearch.py new file mode 100644 index 0000000..9922b4b --- /dev/null +++ b/Code/BinarySearch.py @@ -0,0 +1,34 @@ +def BinarySearch(array, low, high, find): + + while low <= high: + + mid = low + (high - low)//2; + + + if array[mid] == find: + return mid + + + elif array[mid] < find: + low = mid + 1 + + + else: + high = mid - 1 + + # If the element is not present it returns -1 + return -1 + + +# Sample array +arr = [ 2, 3, 4, 10, 40 ] +find = 2 + + +found = BinarySearch(arr, 0, len(arr)-1, find) + +if found != -1: + print ("Given element %d is found at index %d" %(find, found)) +else: + print ("Given element is not present in the given array") + From 1fcf797eef362e8496d17ebe313755634bb16acd Mon Sep 17 00:00:00 2001 From: yashwanth Date: Mon, 9 Oct 2017 12:21:14 +0530 Subject: [PATCH 07/17] Added program to find GCD/HCF --- Code/GCD.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Code/GCD.py diff --git a/Code/GCD.py b/Code/GCD.py new file mode 100644 index 0000000..19197fc --- /dev/null +++ b/Code/GCD.py @@ -0,0 +1,8 @@ +d1=int(raw_input("Enter first number:")) +d2=int(raw_input("Enter second number")) +rem=d1%d2 +while rem!=0 : + d1=d2 + d2=rem + rem=d1%d2 +print "gcd of given numbers is : %d" %(d2) From 901c482f357ba3a845d40cb126667490472a6bf6 Mon Sep 17 00:00:00 2001 From: yashwanth Date: Mon, 9 Oct 2017 15:11:57 +0530 Subject: [PATCH 08/17] Divide two numbers using python code --- Code/divide.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Code/divide.py b/Code/divide.py index 38b410a..b4ea620 100644 --- a/Code/divide.py +++ b/Code/divide.py @@ -1,4 +1,14 @@ -def divide(a, b): - return a / b +num1 = input('Enter first number: ') +num2 = input('Enter second number: ') + + + +if num2==0: + print 'Denominator cannot be 0' + +else: + Division=float(num1)/float(num2) + print Division + + -print divide(20, 2) From bddea45a0ddf4efa911aae8af74fb1c78b91b152 Mon Sep 17 00:00:00 2001 From: sknitk <32913634+sknitk@users.noreply.github.com> Date: Thu, 26 Oct 2017 13:18:18 +0530 Subject: [PATCH 09/17] Create max2.py Program to find maximum of 2 numbers --- Code/max2.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Code/max2.py diff --git a/Code/max2.py b/Code/max2.py new file mode 100644 index 0000000..dcd449b --- /dev/null +++ b/Code/max2.py @@ -0,0 +1,9 @@ +#Program to find maximum of 2 numbers +while 1: + n,m=map(int, raw_input()) + k = max(m,n) + print k + print "Do you want to continue(yes/no): " + s=raw_input() + if s=="no": + break From b81da740d40987d2e59a3967805f732048a09267 Mon Sep 17 00:00:00 2001 From: Shaurya Chaturvedi Date: Thu, 26 Oct 2017 23:22:26 +0530 Subject: [PATCH 10/17] Solves #8 --- Code/division.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Code/division.py diff --git a/Code/division.py b/Code/division.py new file mode 100644 index 0000000..65780fd --- /dev/null +++ b/Code/division.py @@ -0,0 +1,8 @@ + +firstnum = int(input("First number: ")) +secondnum = int(input("Second number: ")) + +if secondnum == 0: + print("Division by zero illegal.") +else: + print("The result is " + str(firstnum/secondnum)) \ No newline at end of file From f496de9cee4c91988055f4443204af30ca38b7b3 Mon Sep 17 00:00:00 2001 From: Aashay Date: Sun, 29 Oct 2017 19:49:24 +0530 Subject: [PATCH 11/17] palindrome code added --- Code/palindrome.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Code/palindrome.py diff --git a/Code/palindrome.py b/Code/palindrome.py new file mode 100644 index 0000000..d289cf5 --- /dev/null +++ b/Code/palindrome.py @@ -0,0 +1,22 @@ +# function which return reverse of a string +def reverse(s): + return s[::-1] + +def isPalindrome(s): + # Calling reverse function + rev = reverse(s) + + # Checking if both string are equal or not + if (s == rev): + return True + return False + + +# Driver code +s = raw_input() +ans = isPalindrome(s) + +if ans == 1: + print("Yes") +else: + print("No") From b4a9ba5e29107070997b524387a2ad38be0173cd Mon Sep 17 00:00:00 2001 From: Aashay Date: Sun, 29 Oct 2017 19:52:57 +0530 Subject: [PATCH 12/17] added initial prompt --- Code/palindrome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/palindrome.py b/Code/palindrome.py index d289cf5..32301c2 100644 --- a/Code/palindrome.py +++ b/Code/palindrome.py @@ -13,7 +13,7 @@ def isPalindrome(s): # Driver code -s = raw_input() +s = raw_input("Enter the string:") ans = isPalindrome(s) if ans == 1: From e52121dc11f075f65638027011b90276b125cd77 Mon Sep 17 00:00:00 2001 From: Aashay Date: Sun, 29 Oct 2017 19:56:40 +0530 Subject: [PATCH 13/17] added code for simple calculator --- Code/calculator.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Code/calculator.py diff --git a/Code/calculator.py b/Code/calculator.py new file mode 100644 index 0000000..77860bf --- /dev/null +++ b/Code/calculator.py @@ -0,0 +1,41 @@ +# 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") + +# Take input from the user +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 dbbc5eb192fe086604a8778b0e835fd43d7b895e Mon Sep 17 00:00:00 2001 From: Aashay Date: Sun, 29 Oct 2017 20:08:52 +0530 Subject: [PATCH 14/17] added code for prime number checker --- Code/primeNumber.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Code/primeNumber.py diff --git a/Code/primeNumber.py b/Code/primeNumber.py new file mode 100644 index 0000000..e387c31 --- /dev/null +++ b/Code/primeNumber.py @@ -0,0 +1,22 @@ +# Python program to check if the input number is prime or not + +num = 407 + +# 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 8a6dfb73d39859b79fe86e8c9eecf0e736b9a900 Mon Sep 17 00:00:00 2001 From: Aashay Date: Sun, 29 Oct 2017 20:10:55 +0530 Subject: [PATCH 15/17] added code for random number generator --- Code/randomNumber.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Code/randomNumber.py diff --git a/Code/randomNumber.py b/Code/randomNumber.py new file mode 100644 index 0000000..4dfeb5c --- /dev/null +++ b/Code/randomNumber.py @@ -0,0 +1,6 @@ +# Program to generate a random number between 0 and 9 + +# import the random module +import random + +print(random.randint(0,9)) From db00ea6f0d22f92d1aa73c553a8f769231a396e3 Mon Sep 17 00:00:00 2001 From: Shikhar Pahadia Date: Mon, 30 Oct 2017 23:31:56 +0530 Subject: [PATCH 16/17] first commit --- Code/add.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Code/add.py diff --git a/Code/add.py b/Code/add.py new file mode 100644 index 0000000..6264050 --- /dev/null +++ b/Code/add.py @@ -0,0 +1,4 @@ +n = int(input('Enter firstnum:')) +m = int(input('Enter secondnum:')) + +print('Sum ' + str(m+n)) \ No newline at end of file From a1c30ab9a92265b81dc7123d9902243467ebd628 Mon Sep 17 00:00:00 2001 From: Harendra Singh Date: Thu, 23 Nov 2017 00:38:33 +0530 Subject: [PATCH 17/17] Revert "first commit" --- Code/add.py | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 Code/add.py diff --git a/Code/add.py b/Code/add.py deleted file mode 100644 index 6264050..0000000 --- a/Code/add.py +++ /dev/null @@ -1,4 +0,0 @@ -n = int(input('Enter firstnum:')) -m = int(input('Enter secondnum:')) - -print('Sum ' + str(m+n)) \ No newline at end of file