Problem in python's print

2

I have 2 inputs that receive the first and last name of a person, then the values entered are entered and the age is requested, but the print is showing name information between " Brackets ". How can I remove?

This is the output

Type your first name: elvis
Type your last name: da silva
['Elvis'] ['Da', 'Silva'], Type your age: 18

This is the code

first_name = str(input('Type your first name: ').split())
last_name = str(input('Type your last name: ').split())

age = int(input('{}, Type your age: '.format(str(first_name+" "+str(last_name)).title())))
    
asked by anonymous 01.01.2019 / 17:57

1 answer

3

The split is the cause of the "problem", when using it you convert the string to a list, see an example:

name = 'Foo'

print(type(name))
<class 'str'>

print(name)
Foo

name = name.split()
print(type(name))
<class 'list'>

print(name)
['Foo']

last_name = 'Bar'
last_name = str(last_name.split()) # O que vc esta fazendo

print(type(last_name))
<class 'str'>

print(last_name)
['Bar']

You could do it in several ways, one of the simplest would be:

first_name = input('Type your first name: ')
last_name = input('Type your last name: ')

age = int(input('{} {}, Type your age: '.format(first_name, last_name)))

Note that there is no need to use str() in input because it already converts automatically to string.

    
01.01.2019 / 18:15