├── 20230616.vignesh.ramesh.alagappa_govt_arts_college_karaikudi.zip ├── calculator .c └── code file.py /20230616.vignesh.ramesh.alagappa_govt_arts_college_karaikudi.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vigneshr1422/exeter-coding-challenge/19a48506547fc0af722f2db1e144c7979b764103/20230616.vignesh.ramesh.alagappa_govt_arts_college_karaikudi.zip -------------------------------------------------------------------------------- /calculator .c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | int main() 5 | { 6 | 7 | while (1) { 8 | printf("Enter an operator (+, -, *, /), " 9 | "exit x: "); 10 | scanf(" %c", &ch); 11 | if (ch == 'x') 12 | exit(0); 13 | printf("Enter two first and second operand: "); 14 | scanf("%lf %lf", &a, &b); 15 | switch (ch) { 16 | case '+': 17 | printf("%.1lf + %.1lf = %.1lf\n", a, b, a + b); 18 | break; 19 | 20 | case '-': 21 | printf("%.1lf - %.1lf = %.1lf\n", a, b, a - b); 22 | break; 23 | 24 | case '*': 25 | printf("%.1lf * %.1lf = %.1lf\n", a, b, a * b); 26 | break; 27 | 28 | case '/': 29 | printf("%.1lf / %.1lf = %.1lf\n", a, b, a / b); 30 | break; 31 | 32 | default: 33 | printf( 34 | "Error\n"); 35 | } 36 | 37 | printf("\n"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /code file.py: -------------------------------------------------------------------------------- 1 | 2 | def load_dictionary(dictionarydoc): 3 | with open(dictionarydoc, 'r') as file: 4 | reader = csv.reader(file) 5 | for row in reader: 6 | english_word, french_word = row 7 | dictionary[english_word] = french_word 8 | return dictionary 9 | def get_process_memory_size(): 10 | process = psutil.Process() 11 | memory_info = process.memory_info() 12 | memory_usage = memory_info.rss / ( 1024 * 1024 ) 13 | return memory_usage 14 | def replace_words(inputdoc, finddocx, dictionarydoc, outputdoc): 15 | dictionary = load_dictionary(dictionarydoc) 16 | start_time = time.time() 17 | with open(inputdoc, 'r') as input_doc, open(outputdoc, 'w') as output_doc, open(finddocx, 'r') as find_words_doc, open("frequency.csv", 'w') as frequency_doc: 18 | words_to_replace = find_words_doc.read().splitlines() 19 | num_replacements = 0 20 | replaced_words = set() 21 | frequency_writer = csv.writer(frequency_doc) 22 | frequency_writer.writerow(["English word", "French word", "Frequency"]) 23 | frequency_count = {} 24 | 25 | for line in input_doc: 26 | words = line.split() 27 | replaced_line = [] 28 | for word in words: 29 | if word in words_to_replace: 30 | if word in dictionary: 31 | word = dictionary[word] 32 | num_replacements += 1 33 | replaced_words.add(word) 34 | 35 | if word not in frequency_count: 36 | frequency_count[word] = 1 37 | else: 38 | frequency_count[word] += 1 39 | else: 40 | print(f"Warning: No translation found for word '{word}'") 41 | replaced_line.append(word) 42 | replaced_line = ' '.join(replaced_line) 43 | output_doc.write(replaced_line + '\n') 44 | 45 | for english_word, french_word in dictionary.items(): 46 | frequency_writer.writerow([english_word, french_word, frequency_count.get(french_word, 0)]) 47 | 48 | end_time = time.time() 49 | time_taken = end_time - start_time 50 | memory_usage = get_process_memory_size() 51 | print(f"Number of times a word was replaced: {num_replacements}") 52 | print(f"Time taken for this process: {time_taken:.2f} seconds") 53 | print("Unique list of words that were replaced with French words from the dictionary: \t", ', '.join(replaced_words)) 54 | print(f"Total memory size of the process: {memory_usage:.2f} MB") 55 | inputdoc = 't8.shakespeare.txt' 56 | finddocx = 'find_words.txt' 57 | dictionarydoc = 'french_dictionary.csv' 58 | outputdoc = 'output.txt' 59 | 60 | replace_words(inputdoc, finddocx, dictionarydoc, outputdoc) 61 | --------------------------------------------------------------------------------