diff --git a/##1_w3_melnikov.py b/##1_w3_melnikov.py new file mode 100644 index 0000000..6e6d0af --- /dev/null +++ b/##1_w3_melnikov.py @@ -0,0 +1,30 @@ +# ## Assignment 1 + +# Write a Python function that prints out the first n rows of Pascal's triangle. +# Note : Pascal's triangle is an arithmetic and geometric figure first imagined by Blaise Pascal. +# Sample Pascal's triangle : +# ![pascal-traingle](https://user-images.githubusercontent.com/45574672/215293769-36573e97-fb93-4ed9-8574-17db7ee04cb7.png) +# Pascal's triangle +# Each number is the two numbers above it added together + +def pascal_triangle(s): + '''Returns n's row in Pascal's triangle + Print included function''' + + #create triangle as nested list of numbers + l, triangle = [1], [[1]] + for _ in range(s): + l = [a + b for a, b in zip([*l, 0], [0, *l])] + triangle.append(l) + + # define base of triangle + basis = len(' '.join(map(str, triangle[-1]))) + for i in triangle: + print(' '.join(map(str, i)).center(basis)) + # print(.center(basis)) + +#call the function +n = int(input('How many rows? ')) - 1 +pascal_triangle(n) + + diff --git a/##2_w3_melnikov.py b/##2_w3_melnikov.py new file mode 100644 index 0000000..ad4da80 --- /dev/null +++ b/##2_w3_melnikov.py @@ -0,0 +1,12 @@ +## Assignment 2 +# Write a Python program that accepts a hyphen-separated sequence of words +# as input and prints the words in a hyphen-separated sequence after sorting them alphabetically. +# Sample Items : green-red-yellow-black-white +# Expected Result : black-green-red-white-yellow + +def alphaSort(string): + '''Returns the words in a hyphen-separated sequence after sorting them alphabetically''' + return '-'.join(sorted(string.split("-"))) + +string = input('Enter your string here... ') +print(alphaSort(string)) \ No newline at end of file diff --git a/##3_w3_melnikov.py b/##3_w3_melnikov.py new file mode 100644 index 0000000..7c0aa21 --- /dev/null +++ b/##3_w3_melnikov.py @@ -0,0 +1,21 @@ +# ## Assignment 3 +# Write a Python function to check whether a number is perfect or not. +# According to [Wikipedia](https://en.wikipedia.org/wiki/Perfect_number) : +# In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, +# that is, the sum of its positive divisors excluding the number itself (also known as its aliquot sum). +# Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself). +# Example : The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors, and 1 + 2 + 3 = 6. +# Equivalently, the number 6 is equal to half the sum of all its positive divisors: ( 1 + 2 + 3 + 6 ) / 2 = 6. +# The next perfect number is 28 = 1 + 2 + 4 + 7 + 14. This is followed by the perfect numbers 496 and 8128. + +def perfect_number(number): + '''Check if the integer number is perfect and returns bolean''' + sum = 0 + for i in range(1, number): + if number % i == 0: + sum += i + return ('NOT PERFECT', 'PERFECT')[sum == number] + +#call the function with integer input +num = int(input('Number ')) +print(perfect_number(num)) \ No newline at end of file diff --git a/#Bon1_w3_melikov.py b/#Bon1_w3_melikov.py new file mode 100644 index 0000000..f287d15 --- /dev/null +++ b/#Bon1_w3_melikov.py @@ -0,0 +1,18 @@ +# Write a Python program to sort a list of dictionaries using Lambda. +# Original list of dictionaries : +# [{'make': 'Nokia', 'model': 216, 'color': 'Black'}, +# {'make': 'Mi Max', 'model': '2', 'color': 'Gold'}, +# {'make': 'Samsung', 'model': 7, 'color': 'Blue'}] + +# Sorting the List of dictionaries : +# [{'make': 'Nokia', 'model': 216, 'color': 'Black'}, +# {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, +# {'make': 'Mi Max', 'model': '2', 'color': 'Gold'}] + + +original = [{'make': 'Nokia', 'model': 216, 'color': 'Black'}, + {'make': 'Mi Max', 'model': '2', 'color': 'Gold'}, + {'make': 'Samsung', 'model': 7, 'color': 'Blue'}] + +original.sort(key=lambda x: x['color']) +print(*original, sep='\n') diff --git a/#Bon2_w3_melnikov.py b/#Bon2_w3_melnikov.py new file mode 100644 index 0000000..be64a00 --- /dev/null +++ b/#Bon2_w3_melnikov.py @@ -0,0 +1,18 @@ +### Bonus 2 +# Write a Python program to filter a list of integers using Lambda. + +# Original list of integers: +# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + +# Even numbers from the said list: +# [2, 4, 6, 8, 10] + +# Odd numbers from the said list: +# [1, 3, 5, 7, 9] + +original = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +even = list(filter(lambda x: not x%2, original)) +odd = list(filter(lambda x: x%2, original)) + +print(even) +print(odd) \ No newline at end of file diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..540d82a Binary files /dev/null and b/.DS_Store differ diff --git a/password_creator_melnikov/.DS_Store b/password_creator_melnikov/.DS_Store new file mode 100644 index 0000000..106dfad Binary files /dev/null and b/password_creator_melnikov/.DS_Store differ diff --git a/password_creator_melnikov/__pycache__/passfunc.cpython-310.pyc b/password_creator_melnikov/__pycache__/passfunc.cpython-310.pyc new file mode 100644 index 0000000..c187f1e Binary files /dev/null and b/password_creator_melnikov/__pycache__/passfunc.cpython-310.pyc differ diff --git a/password_creator_melnikov/creator.py b/password_creator_melnikov/creator.py new file mode 100644 index 0000000..b0e063a --- /dev/null +++ b/password_creator_melnikov/creator.py @@ -0,0 +1,56 @@ +import tkinter as tk +import passfunc as pf +from tkinter import messagebox + +def getint(x): + return int(x.get()) + +def clicked(): + messagebox.showinfo( + message=f'''There is your safe password \n \ + {pf.generate_password(getint(length_p), numlet=getint(number_let), char=chk_char.get())} \n \ + Copy it in the safe place.''') + +screen = tk.Tk() +title = screen.title('Password Creator') +screen.geometry('400x270') + + +#label +label = tk.Label(screen, text='The password will contain uppercase \n and lowercase Latin letters as well \n as numbers and symbols.', font=('Roboto', 14)) +label.pack(padx=20, pady=30) + + +#greed with inputs, labelframe +labelframe = tk.Frame(screen) +labelframe.columnconfigure(0, weight=1) +labelframe.columnconfigure(1, weight=1) + +label1 = tk.Label(labelframe, text='Password Legnth', font=("Roboto", 12)) +label1.grid(row=0, column=0, sticky=tk.W+tk.E) + +length_p = tk.Entry(labelframe, font=('Roboto', 12), width=10) +length_p.grid(row=0, column=1, sticky=tk.W+tk.E) + +label2 = tk.Label(labelframe, text='Number of letters', font=('Roboto', 12)) +label2.grid(row=1, column=0, sticky=tk.W+tk.E) + +number_let = tk.Entry(labelframe, font=('Roboto', 12), width=10) +number_let.grid(row=1, column=1, sticky=tk.W+tk.E) + +chk_char = tk.BooleanVar() +chk_char.set(True) +ischaruse = tk.Checkbutton(labelframe, text='Use special characters', var=chk_char) +ischaruse.grid(row=2, column=1) +labelframe.pack() + +#button frame +buttonframe = tk.Frame(screen) + +submit_button = tk.Button(buttonframe, text='Submit', font=('Roboto', 14), command=clicked) +submit_button.config(height= 20, width=26) +submit_button.pack(pady=20) + +buttonframe.pack() + +screen.mainloop() \ No newline at end of file diff --git a/password_creator_melnikov/passfunc.py b/password_creator_melnikov/passfunc.py new file mode 100644 index 0000000..46a6470 --- /dev/null +++ b/password_creator_melnikov/passfunc.py @@ -0,0 +1,34 @@ +# ## Assignment 4 + +# Create a user interface that generates a random password with the given user input such as length, +# number of lowercase letters and uppercase letters and adding special characters(!,?, .,etc.) + + +import random as ran +import string as st + + +def generate_password(length, numlet=4, char=True): + '''Returns a password consisting of lowercase and uppercase English letters, + numbers and symbols, except for those easily confused with each other''' + + length = int(length) + digits = [digit for digit in st.digits if digit not in '0'] + letters = [letter for letter in st.ascii_letters if letter not in 'lIoO'] + characters = [char for char in st.punctuation] + + password = ran.sample(letters, numlet) + if char==True: + password += ran.sample(characters, 1) + ran.sample(digits, length-numlet-1) + else: + password += ran.sample(digits, length-numlet) + + + ran.shuffle(password) + return "".join(password) + + +def generate_passwords(count, length): + passwords = [generate_password(int(length)) for _ in range(int(count))] + return passwords +