COM1001 – COMPUTER ENGINEERING DEPARTMENT (Solution)

$ 29.99
Category:

Description

Computer Programming 1
LAB3 Quiz
Assoc. Prof. Dr. Hacer YALIM KELEŞ

Write a Python program which takes a sequence of inputs that contain multiple source strings and multiple query strings; prints the occurrences of query strings within the source strings. The output format is speci<ied below. Please also look at the sample I/O <iles.
Speci&ication details:
– Source and query strings will be provided in two different lines. The number of strings are not <ixed, i.e. can change in different runs.
– You can assume that there will be at least one source string and one query string.
– If there are no occurrences of the query strings within any source string, you will print None.
– You will be printing the occurrences in the order that checks for each source sting, all the query strings. (Check your results with the sample outputs for compatibility of the order)
Constraints:
– You are not allowed to use any string class func1ons, such as str.find() or similar. You are expected to implement your own algorithm by itera1ng over the string content as in the previous lab assignment.
– You are not allowed to import any modules that helps iden1fica1on of substrings as well. We will go over the source files one by one and if we iden1fy any external library func1ons in your source codes, we will treat your submission as chea1ng and you will get 0.
Hints:
This 1me, since we have recently learned lists, you will read the strings given in a line using:
inputs = input().split()
ACer reading, inputs variable is bound to a list of strings. You can iterate over the individual items using in operator in a for loop, i.e. for item in inputs:.
You are expected to implement your own solu1ons to determine every occurrences of each query strings within the source strings. As we have seen, you can iterate over individual characters of a string, str, using in operator; e.g. for chr in str:. Alterna1vely, you can use len() func1on and range() func1on in itera1ons within strings.
I personally suggest that, first write this func1on and test it providing different string pairs. ACer making sure that your substring iden1fica1on func1on works without problems, you can very efficiently implement the parts that integrates input reading and output formaNng etc., in quite a short amount of 1me. In every new step, such as reading the inputs part, check if everything is fine by monitoring the content that you read (like prin1ng temporarily or debugging etc.).
I/O Format:
Input format:
[[string][Space]]+ [Newline] [[string][Space]]+
Output format:
Repeat for each occurrence i:
<source_string_i>[space]<query_string_i>[space]<total_number_of_occurrences_in_source_i>[space
]<start_indexes_list>[Newline] if no occurrences are found: None
Note that:
1- Sample input and output files are provided.
2- [x]+ means, one or more elements of x
TesWng:
You are provided with some sample I/O files. Assume that input.txt stands for a sample input and output.txt stands for the corresponding output file and your source code is named as Lab3.py; you can test your program from the command line using the following commands. (>: stands for command prompt)
> python Lab3.py < input.txt > my_output.txt
This command redirects the inputs in the input.txt file as if they are provided from the command line to your python code. The outputs, which you generate using the print() func1on in your source codes, are redirected to my_output.txt file.
You can then check if my_output.txt file is exactly the same with the provided output.txt file, using diff command from the command prompt:
> diff output.txt my_output.txt
Submission:
1- Name your Python source file as <student_id>.py; replace <student_id> using your student id number.
2- Upload your python file using the interface provided in e-kampüs course page.

Reviews

There are no reviews yet.

Be the first to review “COM1001 – COMPUTER ENGINEERING DEPARTMENT (Solution)”

Your email address will not be published. Required fields are marked *