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
49 changes: 49 additions & 0 deletions 24.1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from tkinter import *

def func(x, eps):
y = 1
y_0 = 1
n = 2
while abs(y_0) >= eps:
y_0 = (-1)**(n+1) * n * x**(n-1)
y += y_0
print(y)
n += 1

return y

def calc():
x = float(x_entry.get())
eps = float(eps_entry.get())
assert abs(x) < 1, result_label.configure(text='Warning! |x| < 1')
assert eps > 0, result_label.configure(text='Warning! eps > 0')
ans = func(x, eps)
result_label.configure(text=f'Result: {ans}')

top = Tk()

# X
x_frame = Frame(top)
x_frame.pack()
Label(x_frame, font=('arial', 16), text=' X: ').pack(side=LEFT)
x_entry = Entry(x_frame, font=('arial', 16))
x_entry.pack()

# Eps
eps_frame = Frame(top)
eps_frame.pack()
Label(eps_frame, font=('arial', 16), text='Eps: ').pack(side=LEFT)
eps_entry = Entry(eps_frame, font=('arial', 16))
eps_entry.pack()

# Result
result_frame = Frame(top)
result_frame.pack()
result_label = Label(result_frame, font=('arial', 16), text='Result: ')
result_label.pack(side=LEFT)

# Button
calc_button = Button(top, font=('arial', 16), text="Calculate", command=calc)
calc_button.pack()

top.mainloop()
30 changes: 30 additions & 0 deletions 24.2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from tkinter import *

def is_palindrome(s):
if s == s[::-1]:
return 'YES'
else:
return 'NO'

def check():
s = string_entry.get()
ans = is_palindrome(s)
ans_label.configure(text=f'Is palindrome: {ans}')

top = Tk()

# String
string_frame = Frame(top)
string_frame.pack()
Label(string_frame, font=('arial', 16), text='Input string: ').pack(side=LEFT)
string_entry = Entry(string_frame, font=('arial', 16))
string_entry.pack()

# Answer
ans_label = Label(top, font=('arial', 16), text='Is palindrome: ')
ans_label.pack()

# Button
Button(top, font=('arial', 16), text='Check string', command=check).pack()

top.mainloop()
28 changes: 28 additions & 0 deletions 24.3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from tkinter import *

def diff_words(s):
return set(s.split())

def make_list():
string = diff_words(string_entry.get())
words_list.delete(0, END)
for word in string:
words_list.insert(END, word)
words_list.pack()

top = Tk()

# String
string_frame = Frame(top)
string_frame.pack()
Label(string_frame, font=('arial', 16), text='Input string: ').pack(side=LEFT)
string_entry = Entry(string_frame, font=('arial', 16))
string_entry.pack()

# Button
Button(top, font=('arial', 16), text='Accept', command=make_list).pack()

# Words list
words_list = Listbox(top, font=('arial', 16))

top.mainloop()
41 changes: 41 additions & 0 deletions 24.4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from tkinter import *

def sign_changes(nums=[], changes=0):
num = float(number_entry.get())
number_entry.delete(0, END)
if num == 0:
for i in range(len(nums)-1):
if (nums[i] > 0 and nums[i+1] < 0) or (nums[i] < 0 and nums[i+1] > 0):
changes += 1
ans = changes
while nums:
nums.pop()
changes = 0
return ans
else:
nums.append(num)

def execution(ev=None):
ans = sign_changes()
if ans != None:
ans_label.configure(text=f'Number of sign changes: {ans}')
ans_label.pack()

top = Tk()

# Input number
number_frame = Frame(top)
number_frame.pack()
number_label = Label(number_frame, font=('arial', 16), text='Input number: ').pack(side=LEFT)
number_entry = Entry(number_frame, font=('arial', 16))
number_entry.pack()

# Button
accept_button = Button(top, font=('arial', 16), text='Accept', command=execution)
accept_button.pack()
top.bind('<Return>', execution)

# Answer
ans_label = Label(top, font=('arial', 16))

top.mainloop()