Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8d8c761
Added program to find factorial of number #9
seancyw Oct 8, 2017
6bec965
bubblesort using python
Oct 8, 2017
9a3ac3c
Merge branch 'master' into issue_9
HarendraSingh22 Oct 8, 2017
bd786c5
Merge pull request #19 from seancyw/issue_9
HarendraSingh22 Oct 8, 2017
0a9d29a
Add Fibonacci.py
PrateekRanjanSingh Oct 8, 2017
c22df48
Bug Resolved Fibonacci
PrateekRanjanSingh Oct 8, 2017
ac7b9df
Create HCF.py
CrypticGuy Oct 8, 2017
ea485d1
Merge pull request #35 from PrateekRanjanSingh/master
HarendraSingh22 Oct 8, 2017
700de33
Merge pull request #36 from CrypticGuy/master
HarendraSingh22 Oct 8, 2017
f0cd694
Python Code for BinarySearch
naveentata Oct 8, 2017
2d20411
Merge pull request #37 from naveentata/master
HarendraSingh22 Oct 9, 2017
1fcf797
Added program to find GCD/HCF
thotayashwanth123 Oct 9, 2017
901c482
Divide two numbers using python code
thotayashwanth123 Oct 9, 2017
cf0e0ed
Merge pull request #51 from thotayashwanth123/divide
HarendraSingh22 Oct 9, 2017
dfdb312
Merge pull request #21 from ashishkrishan1995/master
HarendraSingh22 Oct 9, 2017
bddea45
Create max2.py
skumrao Oct 26, 2017
b81da74
Solves #8
shauryachats Oct 26, 2017
f496de9
palindrome code added
aashay201297 Oct 29, 2017
b4a9ba5
added initial prompt
aashay201297 Oct 29, 2017
e52121d
added code for simple calculator
aashay201297 Oct 29, 2017
dbbc5eb
added code for prime number checker
aashay201297 Oct 29, 2017
8a6dfb7
added code for random number generator
aashay201297 Oct 29, 2017
db00ea6
first commit
shikharnsit Oct 30, 2017
e5afc91
Merge pull request #114 from shikharnsit/pahad
HarendraSingh22 Nov 22, 2017
a1c30ab
Revert "first commit"
HarendraSingh22 Nov 22, 2017
39ad935
Merge pull request #120 from HarendraSingh22/revert-114-pahad
HarendraSingh22 Nov 22, 2017
3bf53da
Merge pull request #95 from shauryachats/solves8
HarendraSingh22 Nov 22, 2017
0dee783
Merge pull request #105 from aashay201297/random
HarendraSingh22 Nov 22, 2017
eb01d0f
Merge pull request #91 from sknitk/patch-1
HarendraSingh22 Nov 22, 2017
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
34 changes: 34 additions & 0 deletions Code/BinarySearch.py
Original file line number Diff line number Diff line change
@@ -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")

8 changes: 8 additions & 0 deletions Code/GCD.py
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 16 additions & 0 deletions Code/HCF.py
Original file line number Diff line number Diff line change
@@ -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))

25 changes: 25 additions & 0 deletions Code/bubbleSort.py
Original file line number Diff line number Diff line change
@@ -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]),
41 changes: 41 additions & 0 deletions Code/calculator.py
Original file line number Diff line number Diff line change
@@ -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")
16 changes: 13 additions & 3 deletions Code/divide.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions Code/division.py
Original file line number Diff line number Diff line change
@@ -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))
26 changes: 13 additions & 13 deletions Code/factorial.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
def get_factorial(number):
answer = 1 # We start with 1 as usual for finding factorial

for i in range(1, (number+1)): # 1 is added to second argument of range function since it in this syntax loop terminates at the second value without executing for that value.
answer = answer * i

return answer # answer now contains the calculated value
#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 __name__ == '__main__':
number = input("Enter the number : ")
number = int(number)
factorial = get_factorial(number)
print ("The factorial of " + number+ " is = " + factorial)

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)

10 changes: 10 additions & 0 deletions Code/fibonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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))

9 changes: 9 additions & 0 deletions Code/max2.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions Code/palindrome.py
Original file line number Diff line number Diff line change
@@ -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("Enter the string:")
ans = isPalindrome(s)

if ans == 1:
print("Yes")
else:
print("No")
22 changes: 22 additions & 0 deletions Code/primeNumber.py
Original file line number Diff line number Diff line change
@@ -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")
6 changes: 6 additions & 0 deletions Code/randomNumber.py
Original file line number Diff line number Diff line change
@@ -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))