Exemplo n.º 1
0
def main():
    is_continue = True

    while is_continue:
        mode = input('[1] - Count of string occurrences in a text file.\n'
                     '[2] - Replacement of one string for another in a text '
                     'file.\n'
                     'Select the mode. [1 / 2]\n')
        # C:\Users\Artur\Desktop\parsing1.txt
        # 402795
        if mode == '1':
            file_dir = input('File directory:\n')
            string_for_counting = input('String for counting:\n')
            try:
                count = read_file(file_dir, string_for_counting)
            except FileNotFoundError:
                print('Not found file or directory.\n')
                continue
            print(count)
        # C:\Users\Artur\Desktop\parsing2.txt
        # Самым известным «рыбным» текстом является знаменитый Lorem ipsum.
        elif mode == '2':
            file_dir = input('File directory:\n')
            string_for_searching = str(input('String for searching:\n'))
            string_for_replacing = str(input('String for changing:\n'))
            try:
                replace_line(file_dir, string_for_searching,
                             string_for_replacing)
            except FileNotFoundError:
                print('Not found file or directory.\n')
                continue
        elif not mode:
            print('FILE PARSER\n'
                  '1. Enter the mode of the file parser.\n'
                  '2. Enter the requested data\n'
                  '    for mode 1:\n'
                  '    - file directory\n'
                  '    - string for counting\n'
                  '    for mode 2:\n'
                  '    - file directory\n'
                  '    - string for counting\n'
                  '    - string for replacing\n')
        else:
            print('Incorrect input. Enter must contain number of mode.\n')

        answer = str(input('Do you want to continue? [y / yes]\n'))
        is_continue = do_continue(answer)
Exemplo n.º 2
0
def main():
    is_continue = True

    while is_continue:
        print('Enter the size of chessboard.')

        try:
            height = int(input('Height:\n'))
            width = int(input('Width:\n'))
        except ValueError:
            print('Invalid value. Entries must contain only integer numbers.')
            continue

        chess_board = ChessBoard(height, width)
        r_odd, r_even = chess_board.row_generation()
        print_board(height, r_odd, r_even)
        answer = str(input('Do you want to continue? [y / yes]\n'))
        is_continue = do_continue(answer)
Exemplo n.º 3
0
def main():
    is_continue = True

    while is_continue:
        try:
            digit_number = input('Enter the number:\n')
            if not digit_number:
                print('NUMBER TO WORD\n'
                      '1. Number must be positive.\n'
                      '2. Number must be from 0 to 999.\n')
                continue
            word_number = WordNumber(digit_number)
            word = word_number.number_to_word()
            print(word)
        except ValueError:
            print('Entry must contain only positive number from 0 to 999.\n')

        answer = str(input('Do you want to continue? [y / yes]\n'))
        is_continue = do_continue(answer)
Exemplo n.º 4
0
 def test_do_continue_false_string(self):
     """do_continue 'false string' function test"""
     result = do_continue('something weird')
     self.assertFalse(result)
Exemplo n.º 5
0
 def test_do_continue_yes_mixed_case(self):
     """do_continue 'Yes' function test"""
     result = do_continue('Yes')
     self.assertTrue(result)
Exemplo n.º 6
0
 def test_do_continue_yes_upper_case(self):
     """do_continue 'YES' function test"""
     result = do_continue('YES')
     self.assertTrue(result)
Exemplo n.º 7
0
 def test_do_continue_yes_lower_case(self):
     """do_continue 'yes' function test"""
     result = do_continue('yes')
     self.assertTrue(result)
Exemplo n.º 8
0
 def test_do_continue_y_upper_case(self):
     """do_continue 'Y' input function test"""
     result = do_continue('Y')
     self.assertTrue(result)