diff --git a/24.1.py b/24.1.py new file mode 100644 index 0000000..7146806 --- /dev/null +++ b/24.1.py @@ -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() \ No newline at end of file diff --git a/24.2.py b/24.2.py new file mode 100644 index 0000000..0eda179 --- /dev/null +++ b/24.2.py @@ -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() \ No newline at end of file diff --git a/24.3.py b/24.3.py new file mode 100644 index 0000000..fcfad7c --- /dev/null +++ b/24.3.py @@ -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() diff --git a/24.4.py b/24.4.py new file mode 100644 index 0000000..d35fd11 --- /dev/null +++ b/24.4.py @@ -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('', execution) + +# Answer +ans_label = Label(top, font=('arial', 16)) + +top.mainloop() \ No newline at end of file