+ 3
compress text
How can make code to decompress text like this e.g =k2b2 out put=kkbb
15 odpowiedzi
+ 8
Mohammed Hassan ,
this is my description: (we need 2 lines of code only + the input procedure)
> use a for loop that generates numbers starting from 0 upto n => length of input string.
to do so, we can use *range()* to get the indexes we need. arguments for range():
> first argument is 0 (indexes)
> second argument is length of input string
> third argument is the step-width, we use *2*, so we will get each 2nd character from input string
inside the for loop we can do the processing and output:
use print with these *3 arguments*:
> inp[ind] => is the character like `k` at index
> inp[ind+1] => is the number like `2` of repetitions of the character, has to be converted to int
> end='' => ensures that the output is done in the same line
inside the print function we ca now *multiply* the character by the corresponding count.
do a try by yourself. if you get stuck, post your code here.
+ 4
Mohammed Hassan ,
2 nested loops will not work as expected.
> we have to do the task in single *for loop*
+ 3
Try to make it yourself
Tip: for example you can take the characters 2 by 2 (lets calls the character "c" and the number "n"). Next you can print the character "c" "n" times
+ 2
Mohammed Hassan not really. Just make a loop and you'll be able to read all the String. its easy! whats your problem???? show your attempt to solve the problem!
+ 2
Thanks Lothar
You know the my brain thinking for this task currently
2 for loops
One for char
The second of number found in word
+ 1
Ugulberto Sánchez this simple but problem when became full word
+ 1
Mohammed Hassan ,
Clarification needed. Your example shows a repeating pattern of one letter and one digit, but your reply says "problem when became full word".
Show examples of all the different types of input you expect.
Do you need to process something like this?
"rabbit999frog1"
Can the input encode spaces? Punctuation?
"Hello1,1 1World1!1"
+ 1
Rain
There is different between that found in code couch
This is compress text
That challenge is Decompress text
+ 1
Rain
😂😂😂😂😂😂😂😂😂😅
+ 1
Rain bro it is mistake
Yes i change the mistake not for lying but to be correct!
+ 1
Mohammed Hassan ,
After I learned it is an existing Code Coach, I solved it. Here's my solution. There can be other solutions too.
inp = input()
for i in range(0, len(inp), 2):
print(inp[i] * int(inp[i+1]))
0
Mohammed Hassan ,
Are you trying to solve this Code Coach? You should just say that from the beginning and share the link.
https://www.sololearn.com/coach/85?ref=app
0
Mohammed Hassan ,
Read your thread title above!
0
Mohammed Hassan ,
Now you edited the title from "decompress text" to "compress text", but your question body is still how to decompress, just like the title was. Don't be a liar.
You have two threads. One for compress and one for decompress.
This one we are talking in right now is for decompress text.
And this one linked below is for compress text.
https://www.sololearn.com/Discuss/3258686/?ref=app
0
Mohammed Hassan ,
I think you are confused which thread you're writing in. You should edit the title back to the original "decompress text" to match your question body:
"How can make code to decompress text like this
e.g =k2b2 out put=kkbb"