1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Goryan [66]
4 years ago
14

Name format Many documents use a specific format for a person's name. Write a program whose input is: firstName middleName lastN

ame, and whose output is: lastName, firstName middle Initial. If the input is Pat Silly Doe, the output is: Doe, Pat S. If the input has the form firstName lastName, the output is lastName, firstName. If the input is: Julia Clark, the output is: Clark, Julia Note: This lab focuses on strings; using a loop is not necessary.

Computers and Technology
2 answers:
Nina [5.8K]4 years ago
8 0

Answer:

  1. inputName = input("Input your name: ")
  2. nameComp = inputName.split(" ")  
  3. if(len(nameComp) == 3):
  4.    print(nameComp[2] + ", " + nameComp[0] + " " + nameComp[1][0])
  5. elif(len(nameComp) == 2):
  6.    print(nameComp[1] + ", " + nameComp[0])
  7. else:
  8.    print("Invalid name")

Explanation:

The solution code is written in Python 3.

Firstly use input function to prompt user to enter a name (Line 1).

Next, use split method to divide the input name into a list of individual name components (first name, middle name and last name) by using a single space " " as separator (Line 2).

If the length of nameComp is equal to 3 (this means the input name consists of first, middle and last name), print the name in form of lastName, firstName and middle Initial. This can be done by using appropriate index to get the target name component from the nameComp list and reorder them in the print statement (Line 4-5).

If the nameComp is equal to 2 (this means input name only consists of first name and last name), use the similar way as above to use index to get the target name component from the nameComp list and reroder them in the print statement (Line 6-7).

Add one more else condition to handle the situation where invalid name is enter (Line 8-9).

steposvetlana [31]4 years ago
5 0

Answer:

Explanation:

def name(nameString):

   l = nameString.split(' ')

   if len(l)==3:

       firstName=l[0]

       middleName = l[1]

       lastName=l[2]

   else:

       firstName=l[0]

       lastName=l[1]

       middleName=""

   nameFormat=""

   if middleName!="":

       nameFormat = lastName+", "+firstName+", "+middleName[0]+"."

   else:

       nameFormat = lastName+", "+firstName

   return nameFormat

print(name("Pat Silly Doe"))

print(name("Julia Clark"))

You might be interested in
--- is a set of applications that manages the activities and resources of a computer.
hammer [34]
D. System Software 
is responsible for Manage activity 
4 0
3 years ago
The transmission method that sends data to every device on a lan is known as a _____ transmission.
lina2011 [118]
The transmission method that sends data to every device on a lan is known as a broadcast transmission. This type of transmission is also referred toa as <span> one-to-all transmission method. The network carries a message to all devices at the same time.
</span><span>Sometimes broadcasts are a result of network devices continually announcing their presence in the network, so that other devices don't forget who is still a part of the network.</span>
4 0
4 years ago
Read 2 more answers
How to reset windows 7 password without logging in
hammer [34]

Explanation:

<em>.</em><em>Reboot your laptop or PC. </em>

<em>Select the Repair your Computer option and press Enter. </em>

<em>The System Recovery Options window will popup, click System Restore, it will check the data in your Restore Partition and factory reset laptop without password.</em>

4 0
3 years ago
Read 2 more answers
Which XP practice prescribes that "the code [always be] written by two programmers at one machine"?.
damaskus [11]

Answer:

Pair Programming

Explanation:

In Extreme Programming XP, pair programming is a practice in which two programmers work together in a pair at one machine, when writing a code.

One of the two programmers is called the "driver" or developer who writes the code and supervises all the changes made to the program.

The other one is called an "navigator" or observer who provides ideas on how the program should be written, observes or reviews it the program, identify the issues or errors in the code, help in code simplifications.

The two developers implements the program, do coding, review the program and check each other's work. They both are required to be equally skilled in order to implement and test the code. This improves the process of the software development. By working in a pair and reviewing and testing the code together, they develop a better code.

8 0
4 years ago
Designers and graphic artists can print finished publications on a color printer, take them to a professional printer, or post t
solmaris [256]

DTP is the kind of software where designers and graphic artists can print finished publications on a color printer, take them to a professional printer, or post them on the web.

So, the kind of software is called DTP.

7 0
4 years ago
Other questions:
  • What is used for World Wide Web?
    7·1 answer
  • Acomputer with a domain name is called a
    8·1 answer
  • Sometimes, fourth-generation languages (4GLs) are called procedural languages
    9·1 answer
  • The at command is used to _______________.
    15·1 answer
  • Providing incentives for customers to learn more about your service is known as?
    7·1 answer
  • What are the characteristics of good blogs?
    8·1 answer
  • PLS ANSWER ASAP I WILL GIVE BRAINLIEST
    11·1 answer
  • Knowing and understanding the targeted audience is a main compnent to creating a website
    15·1 answer
  • What year was html released?
    11·2 answers
  • What enforces the location in which an app can function by tracking the location of the mobile device?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!