Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Python List in python

Bright

New Coder
Rich (BB code):
<p> friends = []
new_friends = " "
while new_friends != "end":
    new_friends = input ("Please enter a name: ")
    friends.append(new_friends)
print (f"The name is: {friends} />


How do I get the list to print the names on a separate line and also not print end among the list of names.
 
The code has several errors.
1st error you have html code in python.
2nd error, Not sure that that is the best use of a while loop.
3rd error you do not need to define new_friends = " ".
Here is an example code for you to look at

Python:
# Define a list
friends = []

# Start the loop
while True:
    # Get user input
    new_friend = input("Please enter a name:\n>> ")
    # Give a way for user to exit
    if new_friend == 'quit':
        break

    # Append new friend to list
    friends.append(new_friend)

    # Give a message
    print(f'{new_friend} added to list.')
    
# print all friends on one line seperated by comma
print(f'My friends are {", ".join(friends)}')

print("\nMy Friends:")

# Print each friend on a new line
for friend in friends:
    print(friend)


output
Code:
Please enter a name:
>> john
john added to list.
Please enter a name:
>> tammy
tammy added to list.
Please enter a name:
>> lynn
lynn added to list.
Please enter a name:
>> quit
My friends are john, tammy, lynn

My Friends:
john
tammy
lynn
 
Back
Top Bottom