Form a python string

0

I am trying to make a program that allows me to create a word, through letters entered by the user (It is assumed that you enter letters one at a time).

I did it using a list, but when I print I get: ['h', 'o', 'l', 'a'] , and what I do not want to see quotes or commas. Does anyone know how I can solve it?

This is what I did:

palabra=[]
letra=str(input("Ingrese la primer letra de la palabra")) 
while letra!="/":
    palabra.append(letra)
    letra=str(input("Ingrese la primer letra de la palabra"))

print(palabra)
    
asked by Estanislao Ortiz 07.12.2017 в 21:45
source

3 answers

0

As an option, use the .join () method in this way to remove quotation marks and commas:

print(' '.join(palabra))

in this way instead of getting ['h', 'o', 'l', 'a'] , you will get as output:

h o l a
    
answered by 07.12.2017 в 21:53
0

Here the letters are typed, each separated by enter, and to not enter more letters simply enter when it is empty and already.

from sys import stdin

w=[]
while True:
    b=input()
    if b:
        w.append(b)
    else:
        break
a=('')
for i in w:
    a=a+str(i)
print(a)
    
answered by 25.01.2018 в 02:48
0

Another option is that in your loop while , instead of saving the letters in a list, you add them at the end of the string of characters and this can be done with the sign + , used between two characters , what it does is concatenate. Your code would be like this

#Inicializas palabra como una cadena de caracteres vacía
palabra=''
letra=str(input("Ingrese la primer letra de la palabra")) 

while letra!="/":
    #Concatenas cada letra a la palabra
    palabra = palabra + letra
    letra=str(input("Ingrese la primer letra de la palabra"))

print(palabra)

And the result of the print you'll see is hola if the letters you add are h , o , l and a

    
answered by 12.11.2018 в 17:43