diff --git a/Programs/Test/BinaryToDecimal.py b/Programs/Test/BinaryToDecimal.py new file mode 100644 index 0000000..7304c79 --- /dev/null +++ b/Programs/Test/BinaryToDecimal.py @@ -0,0 +1,17 @@ +#Author: OMKAR PATHAK +#This program converts the given binary number to its decimal equivalent + +def binaryToDecimal(binary): + '''This function calculates the decimal equivalent to given binary number''' + binary1 = binary + decimal, i, n = 0, 0, 0 + while(binary != 0): + dec = binary % 10 + decimal = decimal + dec * pow(2, i) + binary = binary//10 + i += 1 + print('Decimal equivalent of {} is {}'.format(binary1, decimal)) + +if __name__ == '__main__': + userInput = int(input('Enter the binary number to check its decimal equivalent: ')) + binaryToDecimal(userInput) diff --git a/Programs/Test/CharCount.py b/Programs/Test/CharCount.py new file mode 100644 index 0000000..ae13486 --- /dev/null +++ b/Programs/Test/CharCount.py @@ -0,0 +1,18 @@ +#Author: OMKAR PATHAK +#This program checks for the character frequency in the given string + +def charFrequency(userInput): + '''This fuction helps to count the char frequency in the given string ''' + userInput = userInput.lower() #covert to lowercase + dict = {} + for char in userInput: + keys = dict.keys() + if char in keys: + dict[char] += 1 + else: + dict[char] = 1 + return dict + +if __name__ == '__main__': + userInput = str(input('Enter a string: ')) + print(charFrequency(userInput)) diff --git a/Programs/Test/Factorial.py b/Programs/Test/Factorial.py new file mode 100644 index 0000000..37b8dbc --- /dev/null +++ b/Programs/Test/Factorial.py @@ -0,0 +1,22 @@ +#Author: OMKAR PATHAK +#This program calculates the factorial of a given number + +def factorial(number): + '''This function calculates the factorial of a number''' + if number == 1 or number == 0: + return 1 + else: + return number * factorial(number - 1) + +def factorial_without_recursion(number): + fact = 1 + while(number > 0): + fact = fact * number + number = number - 1 + print('Factorial of', number,'is: ') + print(fact) + +if __name__ == '__main__': + userInput = int(input('Enter the number to find its factorial: ')) + print('Factorial of', userInput, 'is:', factorial(userInput)) + factorial_without_recursion(userInput) diff --git a/Programs/Test/Fibonacci.py b/Programs/Test/Fibonacci.py new file mode 100644 index 0000000..67133a1 --- /dev/null +++ b/Programs/Test/Fibonacci.py @@ -0,0 +1,24 @@ +#Author: OMKAR PATHAK +#This program calculates the fibonacci series till the n-th term + +def fibonacci(number): + '''This function calculates the fibonacci series till the n-th term''' + if number <= 1: + return number + else: + return (fibonacci(number - 1) + fibonacci(number - 2)) + +def fibonacci_without_recursion(number): + if number == 0: return 0 + fibonacci0, fibonacci1 = 0, 1 + for i in range(2, number + 1): + fibonacci1, fibonacci0 = fibonacci0 + fibonacci1, fibonacci1 + return fibonacci1 + +if __name__ == '__main__': + userInput = int(input('Enter the number upto which you wish to calculate fibonnaci series: ')) + for i in range(userInput + 1): + print(fibonacci(i),end=' ') + + print("\nUsing LOOP:") + print(fibonacci_without_recursion(userInput)) diff --git a/Programs/Test/LCM.py b/Programs/Test/LCM.py new file mode 100644 index 0000000..aa1f5bd --- /dev/null +++ b/Programs/Test/LCM.py @@ -0,0 +1,19 @@ +#Author: OMKAR PATHAK +#This program calculates the LCM of the two numbers entered by the user + +def LCM(number1, number2): + '''This function calculates LCM of two numbers inputed by the user''' + maximum = max(number1, number2) + i = maximum + while True: + if (i % number1 == 0 and i % number2 == 0): + lcm = i + break + i += maximum + + return lcm + +if __name__ == '__main__': + userInput1 = int(input('Enter first number: ')) + userInput2 = int(input('Enter second number: ')) + print('LCM of {} and {} is {}'.format( userInput1, userInput2, LCM(userInput1, userInput2))) diff --git a/Programs/Test/PrimeNumber.py b/Programs/Test/PrimeNumber.py new file mode 100644 index 0000000..485de60 --- /dev/null +++ b/Programs/Test/PrimeNumber.py @@ -0,0 +1,23 @@ +#Author: OMKAR PATHAK +#This program checks whether the entered number is prime or not + +def checkPrime(number): + '''This function checks for prime number''' + isPrime = False + if number == 2: + print(number, 'is a Prime Number') + if number > 1: + for i in range(2, number): + if number % i == 0: + print(number, 'is not a Prime Number') + isPrime = False + break + else: + isPrime = True + + if isPrime: + print(number, 'is a Prime Number') + +if __name__ == '__main__': + userInput = int(input('Enter a number to check: ')) + checkPrime(userInput) diff --git a/Programs/listoperations.py b/Programs/Test/listoperations.py similarity index 100% rename from Programs/listoperations.py rename to Programs/Test/listoperations.py