Пример #1
0
    def _execute_command(self):
        s = self._command_var.get()
        op_code = int(self._op_code)
        if op_code == 2:
            l = read_int_array(s, MIN_VALUE, MAX_VALUE)
            if l is None or len(l) != 2 or l[0] > l[1]:
                messagebox.showerror('Error', 'Wrong numbers')
            else:
                m, n = l[0], l[1]
                self._result_text.set_text(pn.get_random_prime_number(m, n))

        elif op_code == 3:
            value = read_int(s, MIN_VALUE, MAX_VALUE)
            if value is None:
                messagebox.showerror('Error', 'Wrong length of array')
            else:
                import time
                first = time.time()
                array = pn.get_random_prime_array(value)
                end = time.time()
                print('Time of execute method: {0}'.format(end - first))
                self._result_text.set_text(self._dump_json(array))

        elif op_code == 4:
            l = read_int_array(s, MIN_VALUE, MAX_VALUE)
            if l is None:
                messagebox.showerror('Error', 'Wrong array')
            else:
                self._result_text.set_text(pn.is_relative_primes(l))

        elif op_code == 5:
            l = read_int_array(s, MIN_VALUE, MAX_VALUE)
            if l is None:
                messagebox.showerror('Error', 'Wrong array')
            else:
                self._result_text.set_text(pn.is_pairwise_primes(l))

        elif op_code == 6:
            value = read_int(s, MIN_VALUE, MAX_VALUE)
            if value is None:
                messagebox.showerror('Error', 'Wrong number')
            else:
                self._result_text.set_text(pn.get_next(value, MAX_VALUE))

        elif op_code == 7:
            value = read_int(s, MIN_VALUE, MAX_VALUE)
            if value is None:
                messagebox.showerror('Error', 'Wrong number')
            else:
                self._result_text.set_text(pn.get_prev(value, MIN_VALUE))

        elif op_code == 8:
            value = read_int(s, MIN_VALUE, MAX_VALUE)
            if value is None:
                messagebox.showerror('Error',
                                     'Value must be in range(1, 10^9)')
            else:
                self._result_text.set_text(pn.is_prime(value))
Пример #2
0
 def _gen_number(self):
     self._number_var.set(pn.get_random_prime_number(2, pn.MAX_NUMBER))
Пример #3
0
    print("8. Is prime(number)")
    print("9. Quit")
    print("Select item:", end=' ')


if __name__ == "__main__":
    while True:
        menu()
        s = input()
        op_code = read_int(s, MIN_VALUE, MAX_VALUE)
        if op_code is None:
            print("Unknow command!\n\n")
            continue

        elif op_code == 1:
            print(pn.get_random_prime_number(2, MAX_VALUE))
            input("Enter for continue...")

        elif op_code == 2:
            s = input("Enter min, max values: ")
            l = read_int_array(s, MIN_VALUE, MAX_VALUE)
            if l is None or len(l) != 2 or l[0] > l[1]:
                print("Wrong numbers")
            else:
                m, n = l[0], l[1]
                print(pn.get_random_prime_number(m, n))
            input("Enter for continue...")

        elif op_code == 3:
            s = input("Enter length of array: ")
            value = read_int(s, MIN_VALUE, MAX_VALUE)