diff --git a/assignment-1.py b/assignment-1.py new file mode 100644 index 0000000..979fae0 --- /dev/null +++ b/assignment-1.py @@ -0,0 +1,20 @@ + + +def get_pascal(n): + + for x in range(n+1): + print ("") + + z = 1 + for y in range(1, x+1): + #print(C, ' ', sep='', end='') + print (z , end=" ") + z = z * (x - y) + z = z // y + #print() + + +result = get_pascal(5) +print (result) + + diff --git a/assignment-2.py b/assignment-2.py new file mode 100644 index 0000000..c4c6560 --- /dev/null +++ b/assignment-2.py @@ -0,0 +1,15 @@ + +def hyphen_sort (words) : + + + list = words.split ("-") # split by the hyphen + list =sorted(list) + + final = '-'.join(list) #making sorted string + return (final) + + +words = input('enter the words: ') +words = hyphen_sort (words) + +print (words) \ No newline at end of file diff --git a/assignment-3.py b/assignment-3.py new file mode 100644 index 0000000..40818c3 --- /dev/null +++ b/assignment-3.py @@ -0,0 +1,20 @@ + +def is_perfect(n): + + total = 0 + + for x in range (1,n): + if n % x == 0 : + total += x + + if total == n : + return("Yes") + else: + return("No") + + +number = input("enter number: ") +number = int (number) + +print ("is the number perfect: ", end="") +print(is_perfect(number)) \ No newline at end of file diff --git a/assignment-4.py b/assignment-4.py new file mode 100644 index 0000000..2d62fe2 --- /dev/null +++ b/assignment-4.py @@ -0,0 +1,69 @@ +import random +import secrets +import string + +#password_length = 10 +#number_lowercase = 4 +#number_uppercase = 4 +#number_digits = 5 +#number_special_characters = 3 + + +print ("Welcome to password generator!") +print ("How would you like your new password...") +password_length = int (input("enter password length: ")) +number_lowercase = int (input("how many lowercase characters: ")) +number_uppercase = int (input("how many uppercase characters: ")) +number_digits = int (input("how many digits: ")) +number_special_characters = int (input("how many special characters: ")) + + + +def generate_password (password_length, number_lowercase,number_uppercase, number_digits, number_special_characters) : + + letter_lower = string.ascii_lowercase + letters_upper = string.ascii_uppercase + digits = string.digits + special_chars = string.punctuation + + #rand_lower = "" + #rand_upper = "" + #rand_digit = "" + #rand_special = "" + password_char_list = "" + + for x in range(1, number_lowercase) : + password_char_list += random.choice(letter_lower) + + + for x in range(1, number_uppercase) : + password_char_list += random.choice(letters_upper) + + for x in range(1, number_digits) : + password_char_list += random.choice(digits) + + + for x in range(1, number_special_characters) : + password_char_list += random.choice(special_chars) + + + + + #print (password_char_list) + + + final_password = [] + for x in range(password_length): + + random_char = random.choice(password_char_list) + final_password.append(random_char) + + + + final_password = "".join(final_password) + + print(final_password) + + +print ("your new password is: ", end="") +generate_password (password_length, number_lowercase,number_uppercase, number_digits, number_special_characters) diff --git a/bonus-1.py b/bonus-1.py new file mode 100644 index 0000000..70779a7 --- /dev/null +++ b/bonus-1.py @@ -0,0 +1,9 @@ +dictionaries = [{'make': 'Nokia', 'model': 216, 'color': 'Black'}, +{'make': 'Mi Max', 'model': '2', 'color': 'Gold'}, +{'make': 'Samsung', 'model': 7, 'color': 'Blue'}] + +# the output shown in the readme file suggests it's sorting by "color" key? +sorted = sorted(dictionaries, key = lambda x:x["color"]) + + +print (sorted) \ No newline at end of file diff --git a/bonus-2.py b/bonus-2.py new file mode 100644 index 0000000..585803f --- /dev/null +++ b/bonus-2.py @@ -0,0 +1,13 @@ +list_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + + +#even_list = sorted( lambda x: x %2 != 0) + +even_list = list( filter(lambda x: x%2 == 0, list_numbers) ) +print("even numbers are: ", even_list) + + +odd_list = list( filter(lambda x:x %2 != 0, list_numbers) ) +print("odd numbers are: ", odd_list) + +