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
30 changes: 30 additions & 0 deletions ##1_w3_melnikov.py
Original file line number Diff line number Diff line change
@@ -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)


12 changes: 12 additions & 0 deletions ##2_w3_melnikov.py
Original file line number Diff line number Diff line change
@@ -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))
21 changes: 21 additions & 0 deletions ##3_w3_melnikov.py
Original file line number Diff line number Diff line change
@@ -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))
18 changes: 18 additions & 0 deletions #Bon1_w3_melikov.py
Original file line number Diff line number Diff line change
@@ -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')
18 changes: 18 additions & 0 deletions #Bon2_w3_melnikov.py
Original file line number Diff line number Diff line change
@@ -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)
Binary file added .DS_Store
Binary file not shown.
Binary file added password_creator_melnikov/.DS_Store
Binary file not shown.
Binary file not shown.
56 changes: 56 additions & 0 deletions password_creator_melnikov/creator.py
Original file line number Diff line number Diff line change
@@ -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()
34 changes: 34 additions & 0 deletions password_creator_melnikov/passfunc.py
Original file line number Diff line number Diff line change
@@ -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