diff --git a/SalmanFarid_BUKC_BCE7/Lab2/AI-Lab-2.docx b/SalmanFarid_BUKC_BCE7/Lab2/AI-Lab-2.docx new file mode 100644 index 0000000..5fcf7df Binary files /dev/null and b/SalmanFarid_BUKC_BCE7/Lab2/AI-Lab-2.docx differ diff --git a/SalmanFarid_BUKC_BCE7/Lab2/task1.py b/SalmanFarid_BUKC_BCE7/Lab2/task1.py new file mode 100644 index 0000000..b3db53c --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab2/task1.py @@ -0,0 +1,16 @@ +a = int(input("Enter the first number: ")) +b = int(input("Enter the second number: ")) +c = int(input("Enter the third number: ")) + +if 13 <= a <= 19: + a = 0 +if 13 <= b <= 19: + b = 0 +if 13 <= c <= 19: + c = 0 + +result = a + b + c +print(f"First number : {a}") +print(f"Second number : {b}") +print(f"Third number : {c}") +print(f"Sum of entered numbers: {result}") \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab2/task2.py b/SalmanFarid_BUKC_BCE7/Lab2/task2.py new file mode 100644 index 0000000..35233d9 --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab2/task2.py @@ -0,0 +1,27 @@ +def count_characters(string): + lowercase_count = 0 + uppercase_count = 0 + digit_count = 0 + special_symbol_count = 0 + + for char in string: + if char.islower(): + lowercase_count += 1 + elif char.isupper(): + uppercase_count += 1 + elif char.isdigit(): + digit_count += 1 + else: + special_symbol_count += 1 + + return lowercase_count, uppercase_count, digit_count, special_symbol_count + +input_string = input("Enter a string: ") + +lowercase, uppercase, digits, special_symbols = count_characters(input_string) + +print(f"String: {input_string}") +print(f"Lowercase letters count: {lowercase}") +print(f"Uppercase letters count: {uppercase}") +print(f"Digits count: {digits}") +print(f"Special symbols count: {special_symbols}") \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab2/task3.py b/SalmanFarid_BUKC_BCE7/Lab2/task3.py new file mode 100644 index 0000000..dd3f398 --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab2/task3.py @@ -0,0 +1,18 @@ +def calculate_sum_and_average_of_digits(input_string): + digit_sum = 0 + digit_count = 0 + for char in input_string: + if char.isdigit(): + digit_sum += int(char) + digit_count += 1 + if digit_count > 0: + average = digit_sum / digit_count + else: + average = 0 + + return digit_sum, average +input_string = input("Enter a string: ") +sum_of_digits, average_of_digits = calculate_sum_and_average_of_digits(input_string) +print(f"Entered String: {input_string}") +print(f"Sum of digits: {sum_of_digits}") +print(f"Average of digits: {average_of_digits}") \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab2/task4.py b/SalmanFarid_BUKC_BCE7/Lab2/task4.py new file mode 100644 index 0000000..f2f653c --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab2/task4.py @@ -0,0 +1,12 @@ +def diff__largest_and_smallest(values): + if len(values) < 1: + return 0 + + smallest = min(values) + largest = max(values) + + return largest - smallest + +values = [4, 2, 9, 7, 5] +result = diff__largest_and_smallest(values) +print(result) \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab2/task5.py b/SalmanFarid_BUKC_BCE7/Lab2/task5.py new file mode 100644 index 0000000..0a2534a --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab2/task5.py @@ -0,0 +1,10 @@ +import re + +def count_ant(input_string): + match = re.findall(r'a[a-z]t', input_string) + + return len(match) + +input_string = "ant, art, act, agt, dant, dart" +count = count_ant(input_string) +print(count) \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab3/AI-Lab 3.docx b/SalmanFarid_BUKC_BCE7/Lab3/AI-Lab 3.docx new file mode 100644 index 0000000..16dbd75 Binary files /dev/null and b/SalmanFarid_BUKC_BCE7/Lab3/AI-Lab 3.docx differ diff --git a/SalmanFarid_BUKC_BCE7/Lab3/task1.py b/SalmanFarid_BUKC_BCE7/Lab3/task1.py new file mode 100644 index 0000000..b55fd58 --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab3/task1.py @@ -0,0 +1,11 @@ +no_ofrows = 5 + +for i in range(no_ofrows): + for j in range(i + 1): + print("*", end=" ") + print() + +for i in range(no_ofrows - 1, 0, -1): + for j in range(i): + print("*", end=" ") + print() \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab3/task2.py b/SalmanFarid_BUKC_BCE7/Lab3/task2.py new file mode 100644 index 0000000..3d49369 --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab3/task2.py @@ -0,0 +1,13 @@ +def is_divisible_by_5(binary_str): + decimal_no = int(binary_str, 2) + return decimal_no % 5 == 0 + +values = input("Enter a sequence of comma-separated 4-digit binary numbers: ") + +binary_numbers = values.split(',') + +divisible_by_5 = [binary for binary in binary_numbers if is_divisible_by_5(binary.strip())] + +result = ', '.join(divisible_by_5) +print(f"Comma-separated 4-digit binary numbers: {values}") +print("Numbers divisible by 5:", result) \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab3/task3.py b/SalmanFarid_BUKC_BCE7/Lab3/task3.py new file mode 100644 index 0000000..9db4e19 --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab3/task3.py @@ -0,0 +1,27 @@ +month_to_days = { + 'January': 31, + 'February': (28,29), + 'March': 31, + 'April': 30, + 'May': 31, + 'June': 30, + 'July': 31, + 'August': 31, + 'September': 30, + 'October': 31, + 'November': 30, + 'December': 31 +} + +month_name = input("Input the name of the month: ") + +month_name = month_name.strip().title() + +print(f"List of months: January, February, March, April, May, June, July, August, September, October, November, December") +print(f"Input the name of the month: {month_name}") + +if month_name in month_to_days: + days = month_to_days[month_name] + print(f"No. of days: {days} days.") +else: + print("Invalid month name. Please enter a valid month name.") \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab4/AI-Lab4.docx b/SalmanFarid_BUKC_BCE7/Lab4/AI-Lab4.docx new file mode 100644 index 0000000..83218d3 Binary files /dev/null and b/SalmanFarid_BUKC_BCE7/Lab4/AI-Lab4.docx differ diff --git a/SalmanFarid_BUKC_BCE7/Lab4/data.json b/SalmanFarid_BUKC_BCE7/Lab4/data.json new file mode 100644 index 0000000..0f8674d --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab4/data.json @@ -0,0 +1,26 @@ +{ + "students": [ + { + "firstName": "Nikki", + "lastName": "Roysden" + }, + { + "firstName": "Mervin", + "lastName": "Friedland" + }, + { + "firstName": "Aron ", + "lastName": "Wilkins" + } + ], + "teachers": [ + { + "firstName": "Amberly", + "lastName": "Calico" + }, + { + "firstName": "Regine", + "lastName": "Agtarap" + } + ] +} \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab4/task1.py b/SalmanFarid_BUKC_BCE7/Lab4/task1.py new file mode 100644 index 0000000..c41da98 --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab4/task1.py @@ -0,0 +1,8 @@ +from collections import Counter + +counter = Counter({'Math': 81, 'Physics': 83, 'Chemistry': 87}) + +sorted_value = dict(sorted(counter.items(), key=lambda item: item[1], reverse=True)) + +for key, value in sorted_value.items(): + print(f'{key}: {value}') \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab4/task2.py b/SalmanFarid_BUKC_BCE7/Lab4/task2.py new file mode 100644 index 0000000..1f9e4ce --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab4/task2.py @@ -0,0 +1,21 @@ +import json + +original_dict = { + 'students': [ + {'firstName': 'Nikki', 'lastName': 'Roysden'}, + {'firstName': 'Mervin', 'lastName': 'Friedland'}, + {'firstName': 'Aron ', 'lastName': 'Wilkins'} + ], + 'teachers': [ + {'firstName': 'Amberly', 'lastName': 'Calico'}, + {'firstName': 'Regine', 'lastName': 'Agtarap'} + ] +} + +json_file_path = 'data.json' + +with open(json_file_path, 'w') as json_file: + json.dump(original_dict, json_file, indent=4) + +print(f"Original dictionary:\n{original_dict}") +print(f"Json file to dictionary:\n{json.dumps(original_dict, indent=4)}") \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab4/task3.py b/SalmanFarid_BUKC_BCE7/Lab4/task3.py new file mode 100644 index 0000000..f9eb2a6 --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab4/task3.py @@ -0,0 +1,18 @@ +original_list = [ + {'id': '#FF0000', 'color': 'Red'}, + {'id': '#800000', 'color': 'Maroon'}, + {'id': '#FFFF00', 'color': 'Yellow'}, + {'id': '#808000', 'color': 'Olive'} +] + +removed_item = {'id': '#FF0000', 'color': 'Red'} + +new_list = [d for d in original_list if d != removed_item] + +print("Original list of dictionaries:") +for d in original_list: + print(d) + +print("\nRemove id #FF0000 from the list:") +for d in new_list: + print(d) \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab4/task4.py b/SalmanFarid_BUKC_BCE7/Lab4/task4.py new file mode 100644 index 0000000..f13cd21 --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab4/task4.py @@ -0,0 +1,21 @@ +def reverse_words_in_string(input_string): + + words = input_string.split() + + reversed_words = words[::-1] + + reversed_string = ' '.join(reversed_words) + + return reversed_string + +def main(): + + input_string = input("Enter a long string with multiple words: ") + + reversed_string = reverse_words_in_string(input_string) + + print("Reversed string with words in backward order:") + print(reversed_string) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab4/task5.py b/SalmanFarid_BUKC_BCE7/Lab4/task5.py new file mode 100644 index 0000000..8505be0 --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab4/task5.py @@ -0,0 +1,12 @@ +def fibonacci(n): + if n <= 0: + return 0 + elif n == 1: + return 1 + else: + return fibonacci(n - 1) + fibonacci(n - 2) + +n = 6 +result = fibonacci(n) + +print(f"The {n}th Fibonacci number is {result}") \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab4/task6-BFS.py b/SalmanFarid_BUKC_BCE7/Lab4/task6-BFS.py new file mode 100644 index 0000000..753b43c --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab4/task6-BFS.py @@ -0,0 +1,26 @@ +from collections import deque + +def bfs(graph, start): + visited = set() + queue = deque([start]) + + while queue: + node = queue.popleft() + if node not in visited: + print(node, end=' ') + visited.add(node) + queue.extend(neighbour for neighbour in graph[node] if neighbour not in visited) + +graph = { + 'A': ['B', 'C'], + 'B': ['A', 'D', 'E'], + 'C': ['A', 'F'], + 'D': ['B'], + 'E': ['B', 'F'], + 'F': ['C', 'E'] +} + +start_node = 'A' + +print("BFS traversal starting from", start_node) +bfs(graph, start_node) \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/Lab4/task6-DFS.py b/SalmanFarid_BUKC_BCE7/Lab4/task6-DFS.py new file mode 100644 index 0000000..2658bda --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/Lab4/task6-DFS.py @@ -0,0 +1,21 @@ +def dfs(graph, node, visited): + if node not in visited: + print(node, end=' ') + visited.add(node) + for neighbor in graph[node]: + dfs(graph, neighbor, visited) + +graph = { + 'A': ['B', 'C'], + 'B': ['A', 'D', 'E'], + 'C': ['A', 'F'], + 'D': ['B'], + 'E': ['B', 'F'], + 'F': ['C', 'E'] +} + +start_node = 'A' + +print("DFS traversal starting from", start_node) +visited_nodes = set() +dfs(graph, start_node, visited_nodes) \ No newline at end of file diff --git a/SalmanFarid_BUKC_BCE7/README.md b/SalmanFarid_BUKC_BCE7/README.md new file mode 100644 index 0000000..123f773 --- /dev/null +++ b/SalmanFarid_BUKC_BCE7/README.md @@ -0,0 +1,7 @@ +{ + "name": {Salman Farid}, + "batch": {2024}, + "major": {Computer Engineering}, + "githubUsername": {salman403}, + "favoriteLanguage": {htmcl,css,javascript,react} + } \ No newline at end of file