Knowee
Questions
Features
Study Tools

For t5he above code please correct it as Generate User Name Fix getUserName so that it returns the user’s name as "LastName, FirstName" (without the quotes). Capitalise the first letter of the first and last names If the lastname is null, just return firstname without a comma e.g. "John" "Smith" should return "Smith, John"

Question

For t5he above code please correct it as Generate User Name Fix getUserName so that it returns the user’s name as "LastName, FirstName" (without the quotes).

Capitalise the first letter of the first and last names

If the lastname is null, just return firstname without a comma

e.g. "John" "Smith" should return "Smith, John"

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple Python function that should do what you're asking for:

def getUserName(firstName, lastName):
    if lastName:
        return lastName.capitalize() + ', ' + firstName.capitalize()
    else:
        return firstName.capitalize()

This function takes two arguments, firstName and lastName. If lastName is not None (or not null), it returns a string in the format "LastName, FirstName", with the first letter of each name capitalized. If lastName is None (or null), it simply returns the firstName with the first letter capitalized.

This problem has been solved

Similar Questions

Complete the program below. It should:define a function thatasks the user for their first nameasks the user for their last namereturns "x y", where x is their first name and y is their last nameoutputs the result of the function

You included username_list[10] in your code, but username_list only contains five elements. What type of error is this?1 分Syntax errorLogic errorExceptionName error

package test3;public class Test3 { // DO NOT write a main method public static String getUserName (String firstName, String lastName) { // return the user name as LastName, FirstName e.g. Smith, John } … } }

You've been tasked with developing a user registration form for a new social media platform. One of the crucial requirements is to include a field for the user's username. The username must consist of alphabetic characters only(min 3 and max 20) and should be mandatory for all users. Additionally, you want to provide clear instructions to users, prompting them “Enter your full name “ and if a user hovers over the field it should display a tooltip with the message “Please enter your full name as the username“. Which of the following code snippets fulfills all of these requirements?<label for="username">Username:</label><input type="text" id="username" required title="Please enter your full name as the username" placeholder="Enter your full name" pattern='[a-zA-Z]{3,20}'><label for="username">Username:</label><input type="text" id="username" required title="Please enter your full name as the username" placeholder="Enter your full name"><label for="username">Username:</label><input type="text" id="username" required title="Please enter your full name as the username" placeholder="Enter your full name" pattern='[a-zA-Z]'><label for="username">Username:</label><input type="text" id="username" required title="Please enter your full name as the username" placeholder="Enter your name" pattern='[a-zA-Z]{3,20}'>

write a function that accepts 10 users name and phone number and structure your data in such a way that when i input a users name it returns the phone number and if the name doesn't exist it should return 00000

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.