Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hacktoberfest contribution #102

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added SalmanFarid_BUKC_BCE7/Lab2/AI-Lab-2.docx
Binary file not shown.
16 changes: 16 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab2/task1.py
Original file line number Diff line number Diff line change
@@ -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}")
27 changes: 27 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab2/task2.py
Original file line number Diff line number Diff line change
@@ -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}")
18 changes: 18 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab2/task3.py
Original file line number Diff line number Diff line change
@@ -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}")
12 changes: 12 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab2/task4.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab2/task5.py
Original file line number Diff line number Diff line change
@@ -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)
Binary file added SalmanFarid_BUKC_BCE7/Lab3/AI-Lab 3.docx
Binary file not shown.
11 changes: 11 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab3/task1.py
Original file line number Diff line number Diff line change
@@ -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()
13 changes: 13 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab3/task2.py
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab3/task3.py
Original file line number Diff line number Diff line change
@@ -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.")
Binary file added SalmanFarid_BUKC_BCE7/Lab4/AI-Lab4.docx
Binary file not shown.
26 changes: 26 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab4/data.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
8 changes: 8 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab4/task1.py
Original file line number Diff line number Diff line change
@@ -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}')
21 changes: 21 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab4/task2.py
Original file line number Diff line number Diff line change
@@ -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)}")
18 changes: 18 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab4/task3.py
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 21 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab4/task4.py
Original file line number Diff line number Diff line change
@@ -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()
12 changes: 12 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab4/task5.py
Original file line number Diff line number Diff line change
@@ -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}")
26 changes: 26 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab4/task6-BFS.py
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 21 additions & 0 deletions SalmanFarid_BUKC_BCE7/Lab4/task6-DFS.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions SalmanFarid_BUKC_BCE7/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": {Salman Farid},
"batch": {2024},
"major": {Computer Engineering},
"githubUsername": {salman403},
"favoriteLanguage": {htmcl,css,javascript,react}
}