diff --git a/binarysearch.py b/binarysearch.py new file mode 100644 index 0000000..c28240e --- /dev/null +++ b/binarysearch.py @@ -0,0 +1,21 @@ +def binarySearch (arr, l, r, x): + if r >= l: + mid = l + (r - l)/2 + if arr[mid] == x: + return mid + elif arr[mid] > x: + return binarySearch(arr, l, mid-1, x) + else: + return binarySearch(arr, mid + 1, r, x) + else: + return -1 +arr = [ 2, 3, 4, 10, 40 ] +x = 10 + +# Function call +result = binarySearch(arr, 0, len(arr)-1, x) + +if result != -1: + print "Element is present at index % d" % result +else: + print "Element is not present in array" diff --git a/perfect.py b/perfect.py new file mode 100644 index 0000000..1fd22ca --- /dev/null +++ b/perfect.py @@ -0,0 +1,11 @@ +# Python Program to find Perfect Number using For loop + +Number = int(input(" Please Enter any Number: ")) +Sum = 0 +for i in range(1, Number): + if(Number % i == 0): + Sum = Sum + i +if (Sum == Number): + print(" %d is a Perfect Number" %Number) +else: + print(" %d is not a Perfect Number" %Number) \ No newline at end of file diff --git a/special_twodigit.py b/special_twodigit.py new file mode 100644 index 0000000..7616181 --- /dev/null +++ b/special_twodigit.py @@ -0,0 +1,22 @@ +def specialNumber(n): + + # Checking whether entered + # number is 2 digit or not + if (n < 10 or n > 99): + print("Invalid Input! Number", + " should have 2 digits only") + else: + first = n // 10 + last = n % 10 + sum = first + last + pro = first * last + if ((sum + pro) == n): + print(n ," is a Special ", + "Two-Digit Number") + else: + print(n , " is Not a ", + "Special Two-Digit Number") + +# Driver code +n = 59 +specialNumber(n) \ No newline at end of file diff --git a/strong.py b/strong.py new file mode 100644 index 0000000..a13a778 --- /dev/null +++ b/strong.py @@ -0,0 +1,16 @@ +sum1=0 +num=int(input("Enter a number:")) +temp=num +while(num): + i=1 + f=1 + r=num%10 + while(i<=r): + f=f*i + i=i+1 + sum1=sum1+f + num=num//10 +if(sum1==temp): + print("The number is a strong number") +else: + print("The number is not a strong number") \ No newline at end of file