Looping function in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Looping function in python

How do I make a function that does this: squareString(2,6) 23456 34562 45623 56234 62345 Please don’t give the full answer as this is a homework. I would instead like to know what the most useful tools would be. I am treating the numbers as a string and got the first line just fine. Now trying to make a for loop with a counter that goes up to the maximum value (+1) and where in every iteration the first character of the previous line is moved to the end of the string. So far, no luck.

19th Oct 2019, 12:20 PM
MRJN
MRJN - avatar
3 Answers
+ 3
hello MRJN, i think there is no tool that do this and you have to implement your own method. here is how you can do this: 1- the methode parameters are two integers (int start, int end). 2- you have to test if start is equal to end ( in that case do something ) 3- you have to test if start is less than end ( in that case you have to reverse the algorithm ) 4 - you have to treat your string as an array and get the lenght( ex: if start is 2 and end is 6, the array must be [2,3,4,5,6] and it lenght is 5 ) 4- use the lenght to build a valid loop. 5- for each element in the array, let it be the first element of a new array ( ex : i == 4 ). 6- for that element search for the next elements in the first array until the last one, if the lenght of the first array is different than the new one, get elements from the begining of the first array until equality(equality by lenght). hope it helps. best reguards.
20th Oct 2019, 3:04 PM
Bouaoud Mohsine
Bouaoud Mohsine - avatar
+ 1
Create loopa
21st Oct 2019, 9:38 AM
Yogesh Sambharam
Yogesh Sambharam - avatar
0
Use loops And create
21st Oct 2019, 9:39 AM
Yogesh Sambharam
Yogesh Sambharam - avatar