For loops 2 - iterating strings

Download exercises zip

Browse file online

Let’s see some exercise about strings.

Exercise - Impertinence

Given the sequence of characters having a length multiple of 3, write some code which puts into variable triplets all the sub-sequences of three characters

Example - given:

sequence = "IMPERTINENCE"

after your code, it must result:

>>> print(triplets)
['IMP', 'ERT', 'INE', 'NCE']
Show solution

sequence = "IMPERTINENCE" # ['IMP', 'ERT', 'INE', 'NCE'] #sequence = "CUTOUT" # ['CUT', 'OUT'] #sequence = "O_o" # ['O_o'] # write here

Exercise - rosco

✪✪ Given a string word and string repetitions containing only digits, write some code which puts in variable result a string containing all the characters of word repeated by the number of times reported in the corresponding position of repetitions.

Example - given:

word, repetitions = "rosco", "14323"

After your code it must result:

>>> result
Show solution

word, repetitions = "rosco", "14323" # 'roooosssccooo' word, repetitions = "chocolate", "144232312" # 'chhhhooooccooollaaatee' # write here


Go on with exercises about for loops with lists

[ ]: