Python Forum
Help - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Help (/thread-10550.html)



Help - alwillia - May-24-2018

# Your code below...
name = "  "
number_of_names = int(input("How many names do you have: "))

for i in range(number_of_names):
    next = input("Enter Your Name: ")
    name = name + next
    
print ("Your name is:" + name)
The only problem I'm having is I'm not sure how to get the spaces between the names.

I get the following return:
How many names do you have: 3
Enter Your Name: Bob
Enter Your Name: tim
Enter Your Name: Tom
Your name is: BobtimTom


RE: Help - j.crater - May-24-2018

name = name + next
The same way you are concatenating two strings here, you can also concatenate a whitespace character, which is still just a string.


RE: Help - buran - May-24-2018

first of all, please stop such non-descriptive names. you are here on the forum long enough to know that most of the people here ask for help. by using more descriptive thread title it will help people that would like and can help you to do so more quickly.
although j.carter's advise is 100% correct it is better to start using more advanced methods like str.format, or even f-strings (available in python 3.6+) and st.join
# Your code below...
names = []
number_of_names = int(input("How many names do you have: "))
 
for i in range(number_of_names):
    name = input("Enter Your Name: ")
    names.append(name)
     
print ("Your name is: {}".format(' '.join(names))
note that it's not good to use built-in functions (like next) as variable names. this way you overwrite it...