diff --git a/Test123/Add.py b/Test123/Add.py new file mode 100644 index 0000000..d1ce091 --- /dev/null +++ b/Test123/Add.py @@ -0,0 +1,15 @@ +# Author: OMKAR PATHAK +# This program prints the entered message + +def justPrint(text): + '''This function prints the text passed as argument to this function''' + print(text) + a=int(input("Enter a number: ")) + b=int(input("Enter another number: ")) + increment_value = a + b + print("The sum of the two numbers is:", increment_value) + +if __name__ == '__main__': + justPrint('Hello Sindhuja') + + diff --git a/Test123/Factorial.py b/Test123/Factorial.py new file mode 100644 index 0000000..f5262c3 --- /dev/null +++ b/Test123/Factorial.py @@ -0,0 +1,17 @@ +#Author: OMKAR PATHAK +#This program finds the favtorial of the specified numbers +#For example, factorial of 5 = 5*4*3*2*1 = 120 + +def factorial(number): + '''This function finds the factorial of the number passed as argument''' + if number < 0: + print('Invalid entry! Cannot find factorial of a negative number') + if number == 0 or number == 1: + print("Hello") + return 1 + else: + return number * factorial(number - 1) + +if __name__ == '__main__': + userInput = int(input('Enter the Number to find the factorial of: ')) + print(factorial(userInput)) diff --git a/Test123/P13_Palindrome.py b/Test123/P13_Palindrome.py new file mode 100644 index 0000000..6d5aba8 --- /dev/null +++ b/Test123/P13_Palindrome.py @@ -0,0 +1,14 @@ +#Author: OMKAR PATHAK +#This program checks for the palindrome + +def palindrome(string): + '''This function checks the string for palindrome''' + revString = string[::-1] + if string == revString: + print('String is Palindrome') + else: + print('String is not Palindrome') + +if __name__ == '__main__': + userInput = str(input('Enter a string to check for Palindrome: ')) + palindrome(userInput) diff --git a/Test123/P14_CheckGreater.py b/Test123/P14_CheckGreater.py new file mode 100644 index 0000000..88f74b6 --- /dev/null +++ b/Test123/P14_CheckGreater.py @@ -0,0 +1,15 @@ +#Author: OMKAR PATHAK +#This prpgram checks that the given number is greater than all those numbers in th list + +def checkGreater(number): + '''This function checks whether the entered number is greater than those in the list''' + original = [1,2,3,4,5] + original.sort() + if number > original[-1]: + print('Yes, the entered number is greater than those in the list') + else: + print('No, entered number is less than those in the list') + +if __name__ == '__main__': + userInput = int(input('Enter the number to check: ')) + checkGreater(userInput) diff --git a/Test123/P15_Arguments.py b/Test123/P15_Arguments.py new file mode 100644 index 0000000..cd51cf3 --- /dev/null +++ b/Test123/P15_Arguments.py @@ -0,0 +1,17 @@ +#Author: OMKAR PATHAK +#This program gives a demo of how can you pass arguments while running python programs +#Run the program as: python P15_Arguments.py Omkar Pathak + +import sys + +def arguments(): + '''This function prints the argruments passed while running the python program''' + try: + print('This is the name of the script:', sys.argv[0]) + print('First argument:', sys.argv[1]) + print('Second argument:', sys.argv[2]) + except IndexError: + print('Give only two arguments') + +if __name__ == '__main__': + arguments() diff --git a/Test123/P16_CountVowels.py b/Test123/P16_CountVowels.py new file mode 100644 index 0000000..9b0c691 --- /dev/null +++ b/Test123/P16_CountVowels.py @@ -0,0 +1,17 @@ +#Author: OMKAR PATHAK +#This program counts the vowels present in the user input + +def countVowels(sentence): + '''This function counts the vowels''' + count = 0 + sentence = sentence.lower() + for c in sentence: + if c in ['a', 'e', 'i', 'o', 'u']: + count += 1 + return count + + +if __name__ == '__main__': + userInput = str(input("Enter the string to check for vowels: ")) + count = countVowels(userInput) + print('Vowel Count: ',count) diff --git a/Test123/P17_EvenOdd.py b/Test123/P17_EvenOdd.py new file mode 100644 index 0000000..b69a47f --- /dev/null +++ b/Test123/P17_EvenOdd.py @@ -0,0 +1,19 @@ +#Author: OMKAR PATHAK +#This program takes input from user and sorts the numbers in two arrays, one of even and other of odd + +def evenOdd(numbers): + '''This function divides the numbers in two arrays one of even and other of odd''' + even = [] + odd = [] + for number in numbers: + if int(number) % 2 == 0: + even.append(number) + else: + odd.append(number) + return even, odd + +if __name__ == '__main__': + userInput = input("Enter the numbers (space separated) to check: ") + userInput = list(userInput.split()) + even, odd = evenOdd(userInput) + print('Even Nos: ', ','.join(even), '\n', 'Odd Nos: ', ','.join(odd))