How to make it so that Python will input everything first, then take initials after?

write a program that asks the user for his name and greets him with his name in python
python program to print the initials of a name with last name written in full
python first, last name program
how to get string input in python 3
python input integer
you must actually prompt for the users name
python user input choice
if input = python

Basically the title. For some reason, this code prints initials after every input which is not what I want.

num_of_people = int(input("How many people will attend the meeting? "))
for i in range(num_of_people):
    name = input("What is the full name of participant " + str(i+1) + "?")
    split_name = name.split(" ")
    for i in range(len(split_name)):
         name_word = split_name[i]
    print (name_word[0])

I expected it to list all the initials of the people who attended the meeting.

It's printing every single time because you have it inside a single loop. For any program, you want to break it into a set of requirements, and then build up how you can accomplish those requirements. Based on your question, I'm guessing the requirements are:

  1. Accept the number of participants from the user.
  2. Accept the name of each participant from the user and store them.
  3. Display the initials of all participants after all names have been entered.

You satisfy requirement 1 just fine. Requirement 2 is not satisfied. You accept each name and store it for a single loop, but as soon as you get to the next iteration, the name is overwritten. You should have a list that holds each name. For requirement 3, if you want the initials to be displayed after all names have been entered, you need to write that loop last. I'll try to use extra-descriptive variables.

num_of_people = int(input("How many people will attend the meeting? "))
name_list = [] # This will be the list we store each name in.
for i in range(num_of_people):
    name = input(f"What is the full name of participant {i+1}? ")
    # We can use literal f-strings to format strings easier.
    name_list.append(name) # We add the name to our name list
    # This next line is so you can see what's happening. Take it out after.
    print(f"Name list is currently: {name_list}")

# We're done building the name list now. We want to print the initials
print("---Initials---")
for cur_name in name_list: # cur_name is the current name
    split_name = cur_name.split(" ")
    # split_name is now a list of each 'word' from the current name
    # If we want to take the initials only, we need to grab the first
    # element of each word in this list.
    for sub_name in split_name:
        # Now ask yourself how you want it to be formatted?
        # A common way would be with dots between each initial
        initial = sub_name[0]
        print(f"{initial}.", end = "")
        # We add end = "" so that no new-line is printed
    # After we print all the initials for the current name, add a newline.
    print()

Output:

How many people will attend the meeting? 4
What is the full name of participant 1? Pam Beezly Halpert
Name list is currently: ['Pam Beezly Halpert']
What is the full name of participant 2? Michael Scott
Name list is currently: ['Pam Beezly Halpert', 'Michael Scott']
What is the full name of participant 3? Dwight Schrute
Name list is currently: ['Pam Beezly Halpert', 'Michael Scott', 'Dwight Schrute']
What is the full name of participant 4? Holly Flax
Name list is currently: ['Pam Beezly Halpert', 'Michael Scott', 'Dwight Schrute', 'Holly Flax']
---Initials---
P.B.H.
M.S.
D.S.
H.F.

I recommend you take some time and look at tutorials online. There are some great ones at the official site: https://docs.python.org/3/tutorial/

Trying to display initials in Python, If you are on Python 2.x you should exchange input for raw_input. name_list = name.split() print(name_list) first = name_list[0][0] second = name_list[1][0] last I'll try to explain why it occurred rather than just giving you the solution. So you get a difference in the two only on the middle/last name. This function splits the string parameter into a list using the space as a delimiter, then adds the first letter of each item to a temporary list. The temporary list is then joined back together to return the initials as a string. Doing it in this fashion means it will work for middle names and such as well.

Practical Cryptography in Python: Learning Correct Cryptography by , in a loop, iterate through all possible lowercase one-letter inputs. Then try it with three and four symbols at a time. how much longer does it take to invert Rather trivially, there are 26 lowercase letters in ASCII, so 26 one-symbol inputs. If you can have 26 characters for the first symbol and 26 characters for the second  Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.

So we can try something like this:

num_of_people = int(input("How many people will attend the meeting? "))
for i in range(num_of_people):
    name = input("What is the full name of participant " + str(i+1) + "?")
    ## This loop stuff is not needed...
    ## split_name = name.split(" ")
    ## for i in range(len(split_name)):
    ##     name_word = split_name[i]
    print (name[0])

The bug in your code is pointed out in comments, so please have a lot at that :)

Basic Input, Output, and String Formatting in Python – Real Python, In this step-by-step Python tutorial, you'll learn how to take user input from the Free Bonus: Click here to get a Python Cheat Sheet and learn the basics of If you want a numeric type, then you need to convert the string to the Line 8 converts n to an integer so the print() statement on line 10 succeeds. We passed the Python input( ) function as the parameter of the int( ) function. This contraption of nested function call will convert the data type of the value entered by the user from string to an integer before it gets saved into the variable. That is how we take an integer input using Python input function in Python Programming language.

Python Programming: An Introduction to Computer Science, An acronym is a word formed by taking the first letters of the words in a phrase and that allows the user to type in a phrase and then outputs the acronym for that phrase. The total value is just the sum of the numeric values of all the names. 8. The input to the program will be a string of plaintext and the value of the key. 2 How to make it so that Python will input everything first, then take initials after? Sep 19 '19 2 bash: Python import - Command not found for pandas Sep 23 '19

Python for Linguists, The program randomly selects a letter, and then the user can guess letters. is that it gives the user feedback on whether their guess is before or after the selected letter. Thus the number and content of each keyboard input is dependent on the First, we import from the random module to have access to a random number  Python input function allows to user pass content in the program. In a simple word, the program can read the line form console, which entered by users. With the input function, we can read string and integer (Numbers) data type in python.

Experimental Physics: Principles and Practice for the Laboratory, Remember that we're using Python 3, so ignore everything relating to Python 2 all the exercises except the first one, you need to insert a new cell for Python code. following questions easily: Exercise 1 Concept test: Are you more than half a get from the letters you're supposed to select out of “supercalifragilistic,” does  This method affects only the first letter in a string. It changes it to be uppercase. If the first character is not a letter, nothing happens. Here: Please notice that the variable "s" is assigned to the result of capitalize(). Tip: This means capitalize() does not change the existing string in-place. It creates a new copy of the string in

Comments
  • name is overwritten with new input on each iteration of your first loop. You need create a list first, e.g. names = [], and then append to it names.append(name).
  • And then you do not need to split. Just iterate over the list to get each element and get the first letter
  • the print function is in the main for loop, so it executes every loop
  • Plus 1 for breaking it down into requirements. So important. Nice one!
  • Sorry to downvote, but this does not meet the OP's requirements. This only prints the first initial and does not store the initials in a list, as requested. "I expected it to list all the initials of the people who attended the meeting."
  • Oops ! I didn't knew that. And by 'initials' OP meant the first letter of each name?? Bruh, in India (or at least in South India) by initials we mean the first letter before our name and it is our parent's name's first letter. Like my name is J Arun Mani and my initial is J because my father's name in Jeyaraman.... Sorry guys...