This function for selection some string from a file doesn't work for some reason | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

This function for selection some string from a file doesn't work for some reason

This is the code: file = open('new_file.txt', 'r') inpt = file.read() def sort(file): i = 1 # This only for testing!!! num = str(i) + "." num_find = file.find(num) start = file.find(num) a = file.find("A)", num_find) b = file.find("B)", num_find) question = file[start:a] answer = file[a:b] print('Question is: ', question 'Answer is ', answer) sort(inpt) And the file looks like this: 1. ICT stands for: А) Information and Communication Technology B) Integra Common Terminology C) International Communication Technology D) Inter connected Terminals E) Interactive Communication Technology 2. Which of the following is the appropriate definition of Information Technology? A) Information Technology refers to the use of hardware and software for storage, retrieval, processing and distributing information of many kinds. B) Information Technology refers to the use of hardware and software for distribution of useful information. C) Information Technology refers to the use of principles of Physical sciences and Social sciences for processing of information of many kinds. D) Information Technology refers to the use of hardware and software for processing information. E) Information Technology refers to greatly impacted and enhanced global socialization and interactions.

5th May 2019, 6:32 AM
Жанибек Райкулов
Жанибек Райкулов - avatar
1 Answer
0
This function for selection some string from a file doesn't work for some reason This is the code: file = open('new_file.txt', 'r') inpt = file.read() def sort(file): i = 1 # This only for testing!!! num = str(i) + "." num_find = file.find(num) start = file.find(num) a = file.find("A)", num_find) b = file.find("B)", num_find) question = file[start:a] answer = file[a:b] THIS LINE print('Question is: ', question 'Answer is ', answer) sort(inpt) And the file looks like this: 1. ICT stands for: АA) Information and Communication Technology B) Integra Common Terminology C) International Communication Technology D) Inter connected Terminals E) Interactive Communication Technology The line marked by THIS LINE misses a comma after question print('Question is: ', question->,<- 'Answer is ', answer) Also, the A is for some reason different in A) as an encode error forms while execution...
5th May 2019, 8:27 AM
Kartik
Kartik - avatar