I am a beginner in Python, I try to extract from an input what I wrote but I need to extract it in parts, a method that can extract a number of characters that I tell it, I have used this:
código = input() extraer_subcadena1 = código[0:1] However I want each passing through the while loop to change to a different number of characters and I can't do it because I don't know how to make an algorithm that can change this [0:1] to for example this [1:2] each passing for the while loop
for this case I recommend you read about the for loop https://j2logo.com/loop-for-en-python/
for this algorithm what you want is to print an index of the string starting from 0 and ending at the last letter.
First: to know when it measures a string in python, use the len method on a text string. for example I have the string variable and I want to know how many characters it measures then, using the I have method:
cadena = "Hola Mundo" print(len(cadena)) ## El resultado es 10 Once As knowing measuring chain using the cycle is for so that use in this manner (eye, as is an input of the user and does not know how tall is assigned the value of the method len a variable)
codigo = input('Introduce un texto: ') longitud = len(codigo) for letras in range(longitud): #Esta parte se puede simplificar pero haciendolo de este modo podras ver mejor como funciona print(codigo[letras:letras+1])and as output it will give you:
H o l a M u n d o