Skip to content
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
14 changes: 14 additions & 0 deletions Assignment 1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def pascals_triangle(n):
triangle = []
for i in range(n):
if i == 0:
triangle.append([1])
else:
row = [1]
for j in range(1, i):
row.append(triangle[i-1][j-1] + triangle[i-1][j])
row.append(1)
triangle.append(row)

for row in triangle:
print(row)
9 changes: 9 additions & 0 deletions Assignment 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def sort_words(words):
words_list = words.split("-")
words_list.sort()
sorted_words = "-".join(words_list)
return sorted_words

input_words = input("Enter a hyphen-separated sequence of words: ")
sorted_words = sort_words(input_words)
print("Sorted sequence:", sorted_words)
10 changes: 10 additions & 0 deletions Assignment 3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def is_perfect(num):
divisors = []
for i in range(1, num):
if num % i == 0:
divisors.append(i)
sum_of_divisors = sum(divisors)
if sum_of_divisors == num:
return True
else:
return False
21 changes: 21 additions & 0 deletions Assignment 4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import random
import string

def generate_password(length, num_lowercase, num_uppercase, num_special_chars):
password = ''
lowercase_chars = string.ascii_lowercase
uppercase_chars = string.ascii_uppercase
special_chars = '!@#$%^&*()_+-=[]{}'

for i in range(num_lowercase):
password += random.choice(lowercase_chars)
for i in range(num_uppercase):
password += random.choice(uppercase_chars)
for i in range(num_special_chars):
password += random.choice(special_chars)

while len(password) < length:
password += random.choice(lowercase_chars + uppercase_chars + special_chars)

password = ''.join(random.sample(password, len(password)))
return password
9 changes: 9 additions & 0 deletions Bonus 1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
original_list = [{'make': 'Nokia', 'model': 216, 'color': 'Black'},
{'make': 'Mi Max', 'model': '2', 'color': 'Gold'},
{'make': 'Samsung', 'model': 7, 'color': 'Blue'}]

sorted_list = sorted(original_list, key=lambda x: x['make'])

print("Sorted List of dictionaries:")
for item in sorted_list:
print(item)