Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

we are using python [30 marks] Write a function named compress that takes a string as a parameter. This function compresses a string by replacing

we are using python image text in transcribed
image text in transcribed
[30 marks] Write a function named compress that takes a string as a parameter. This function compresses a string by replacing any sequentially repeated letters with a letter and a number where the number indicates how many times the letter was repeated. The function returns the compressed string. For example: > compress(" ") > compress("abc") ' ab ' \> compress("aabbbbccccccc") ' a2b4c7 ' 2) [ 30 marks] Write a function called expand that takes a string in the compressed format and returns the original string. You may assume that any number in the compressed string is a single-digit number. For example: > expand(" ") expand("abc") ' abc expand("a3b7c2") 'aaabbbbbbbcc' [40 marks] Write a function called Write a function named is_basic_expr. This function must accept a string as a parameter and return a Boolean value that indicates whether that string represents a valid basic expression. For this question, assume that valid expressions consist of one or more positive integers that are separated by basic operators (only the operators +,,, and / ). The string must start and end with an integer. Moreover, a single space must always separate integers and operators in a valid expression. For example: \> is_basic_expr("1") True is_basic_expr("1 + 22") True is_basic_expr("1+22 * 333 ") True is_basic_expr("-1") False is_basic_expr("1++22") False is_basic_expr("1 22 * 333") False is_basic_expr("1 ") False is_basic_expr("1 +") False is_basic_expr("1 + ") False is_basic_expr("1 + 22") False NOTE the spaces, in the last example there are 2 spaces before and after the +

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions