diff --git a/TEST CASES.txt b/TEST CASES.txt new file mode 100644 index 0000000..a79bff4 --- /dev/null +++ b/TEST CASES.txt @@ -0,0 +1,136 @@ +1.Test Cases for data_type_ops() function: + +Public Test Cases: +1. **Test Case 1:** + - Input: + - integer = 10 + - float_num = 20.0 + - string = "Hello" + - list_input = [1, 2, 3] + - dictionary = {"key1": "value1"} + - set_input = {1, 2, 3} + - v = 5 + - Expected Output: + - (15.0, 10.0, "HelloKaushik", [1, 2, 3, 4], {"key1": "value1", "new_key": "new_value"}, {1, 2, 3, 5}) + +2. Test Case 2: + - Input: + - integer = 1 + - float_num = 1.0 + - string = "Test" + - list_input = [] + - dictionary = {} + - set_input = set() + - v = 7 + - Expected Output: + - (6.0, 0.5, "TestKaushik", [7], {"new_key": "new_value"}, {7}) + +Private Test Cases: +1.Test Case 1: + - Input: + - integer = -5 + - float_num = 10.0 + - string = "Data" + - list_input = [5, 6] + - dictionary = {"key2": "value2"} + - set_input = {8, 9} + - v = 3 + - Expected Output: + - (0.0, 5.0, "DataKaushik", [5, 6, 3], {"key2": "value2", "new_key": "new_value"}, {8, 9, 3}) + +--- + + 2. Test Cases for num_processor() function: + +Public Test Cases: +1. Test Case 1: + - Input: [1, 2, 3, 4, 5] + - Expected Output: 35 (1^2 + 3^2 + 5^2) + +2. Test Case 2: + - Input: [2, 4, 6, 8] + - Expected Output: 0 (No odd numbers) + +3. Test Case 3: + - Input: [1, 3, 5, 7] + - Expected Output: 84 (1^2 + 3^2 + 5^2 + 7^2) + +4. Test Case 4: + - Input: [] + - Expected Output: 0 (Empty list) + + +Private Test Cases: +1. Test Case 1: + - Input: [10, 15, 20] + - Expected Output: 225 (15^2) + +2. Test Case 2: + - Input: [0, 0, 0] + - Expected Output: 0 (All zeros) + +--- + +3. Test Cases for Vowel Counting Program: + +Public Test Cases: +1. Test Case 1: + - Input: "hello world" + - Expected Output: 3 (e, o, o) + +2. Test Case 2: + - Input: "" + - Expected Output: 0 (Empty string) + +3. Test Case 3: + - Input: "aeiou" + - Expected Output: 5 (a, e, i, o, u) + +4. Test Case 4: + - Input: "bcdfg" + - Expected Output: 0 (No vowels) + +Private Test Cases: +1. Test Case 1: + - Input: "Python" + - Expected Output: 1 (o) + +2. Test Case 2: + - Input: "Supercalifragilisticexpialidocious" + - Expected Output: 16 (All vowels in the string) + +--- + +### 4. **Test Cases for Library Class:** + +#### Public Test Cases: +1. **Test Case 1:** + - Action: Add a book "Python Basics" and "Data Science" + - Expected Output: {"Python Basics": 1, "Data Science": 1} + +2. **Test Case 2:** + - Action: Borrow "Python Basics" + - Expected Output: {"Python Basics": 0, "Data Science": 1} + +3. **Test Case 3:** + - Action: Try to borrow "Python Basics" again (which is unavailable) + - Expected Output: "Sorry, 'Python Basics' is not available." + +4. **Test Case 4:** + - Action: Return "Python Basics" + - Expected Output: {"Python Basics": 1, "Data Science": 1} + +#### Private Test Cases: +1. **Test Case 1:** + - Action: Add "Machine Learning" + - Expected Output: {"Python Basics": 1, "Data Science": 1, "Machine Learning": 1} + +2. **Test Case 2:** + - Action: Borrow "Data Science" + - Expected Output: {"Python Basics": 1, "Data Science": 0, "Machine Learning": 1} + +3. **Test Case 3:** + - Action: Return "Machine Learning" + - Expected Output: {"Python Basics": 1, "Data Science": 0, "Machine Learning": 2} + +These test cases cover a variety of possible inputs and scenarios for each function and class. \ No newline at end of file diff --git a/pythonquestions.py b/pythonquestions.py new file mode 100644 index 0000000..29e9af1 --- /dev/null +++ b/pythonquestions.py @@ -0,0 +1,126 @@ +''' +Write a function data_type_ops() that takes an integer, a float, a string, a list, a dictionary, and a set as input. +The function should perform the following operations: +1. Add 5.0 to the integer. +2. Divide the float by 2 +3. Concatenate the string with your name. +4. Append a new value to the list. +5. Add a new key-value pair to the dictionary with key "new_key" and value "new_value". +6. Add a value v to the set. + +''' + +def data_type_ops(integer, floating, string, lst, dct, st, new_value, v): + + updated_integer = integer + 5.0 + + # 2. Divide the float by 2 + updated_float = floating / 2 + + # 3. Concatenate the string with your name + updated_string = string + " Kaushik" + + # 4. Append a new value to the list + lst.append(new_value) + + # 5. Add a new key-value pair to the dictionary + dct["new_key"] = "new_value" + + # 6. Add a value to the set + st.add(v) + + return updated_integer, updated_float, updated_string, lst, dct, st + +''' +Write a function num_processor() that takes a list of integers and performs the following operations: +1. Filter out all even numbers. +2. Square the remaining odd numbers. +3. Return the sum of the squared numbers. + +''' +def num_processor(num_list): + + # 1. Filter out even numbers + odd_numbers = filter(lambda x: x % 2 != 0, num_list) + + # 2. Square the remaining odd numbers + squared_numbers = [x**2 for x in odd_numbers] + + # 3. Return the sum of the squared numbers + return sum(squared_numbers) + +''' +Write a program that reads a string and prints the number of vowels in it. +''' +def count_vowels(string): + """Count the number of vowels in a string.""" + vowels = "aeiouAEIOU" + count = sum(1 for char in string if char in vowels) + return count + +''' +4. LIBRARY MANAGEMENT SYSTEM +''' + +class Library: + def __init__(self): + self.books = {} + + def add_book(self, book): + + self.books[book] = self.books.get(book, 0) + 1 + print(f'Book "{book}" added to the library.') + + def borrow_book(self, book): + + if self.books.get(book, 0) > 0: + self.books[book] -= 1 + print(f'You borrowed "{book}".') + else: + print(f'Sorry, "{book}" is not available.') + + def return_book(self, book): + + self.books[book] = self.books.get(book, 0) + 1 + print(f'Book "{book}" returned to the library.') + + def display_inventory(self): + + if not self.books: + print("The library is empty.") + else: + print("Current inventory:") + for book, count in self.books.items(): + print(f'{book}: {count} copies') + +def main(): + library = Library() + while True: + print("\nLibrary Management System") + print("1. Add Book") + print("2. Borrow Book") + print("3. Return Book") + print("4. Display Inventory") + print("5. Exit") + + choice = input("Enter your choice: ") + + if choice == "1": + book = input("Enter the name of the book to add: ") + library.add_book(book) + elif choice == "2": + book = input("Enter the name of the book to borrow: ") + library.borrow_book(book) + elif choice == "3": + book = input("Enter the name of the book to return: ") + library.return_book(book) + elif choice == "4": + library.display_inventory() + elif choice == "5": + print("Exiting the Library Management System. Goodbye!") + break + else: + print("Invalid choice. Please try again.") + +if __name__ == "__main__": + main() \ No newline at end of file