For this task, you are to implement a simple compression algorithm. The logic for this particular simple
Question:
For this task, you are to implement a simple compression algorithm.
The logic for this particular simple compression algorithm is shown in the flowchart below: The purpose of the algorithm is to represent text in a way that is more efficient for many repeated characters. See the examples for how this is expected to work.
Using the provided code as a starting point, complete the program so that the behaviour of your code matches the flowchart. The code below is to here to help ans start the process:
# TODO: Fix this code so that it matches the flowchart
inp = input('Text to compress: ')
compressed = '' count = 1 prev_char = inp[0] for char in inp[1:]: if char == prev_char: count = count + 1 compressed = compressed + str(count) + prev_char count = 1
print(compressed)
Physics
ISBN: 978-0077339685
2nd edition
Authors: Alan Giambattista, Betty Richardson, Robert Richardson