HackerRank Python: What’s Your Name? Solution

Table of Contents

Question

You are given the firstname and lastname of a person on two different lines. Your task is to read them and print the following:

Hello firstname lastname! You just delved into python.

Function Description

Complete the print_full_name function in the editor below.

print_full_name has the following parameters:

  • string first: the first name
  • string last: the last name

Prints

  • Prints string: ‘Hello firstname lastname! You just delved into python‘ where and are replaced with first and last.

Input Format

The first line contains the first name, and the second line contains the last name.

Constraints

The length of the first and last names are each ≤ 10.

Sample Input 0

Ross
Taylor

Sample Output 0

Hello Ross Taylor! You just delved into python.

Explanation 0

The input read by the program is stored as a string data type. A string is a collection of characters.

Solution

				
					def print_full_name(first, last):
    print(f"Hello {first} {last}! You just delved into python.")

# Read the first name and last name
first_name = input()
last_name = input()

# Call the print_full_name function with the first name and last name
print_full_name(first_name, last_name)

				
			
  1. We define a function called print_full_name that takes two strings as input: first for the first name and last for the last name.
  2. Inside the function, we use an f-string to format and print the desired message. The f-string allows us to directly embed the values of first and last into the string using curly braces {}.
  3. In the main part of the code, we read the first name and last name from input using the input() function.
  4. We then call the print_full_name function, passing the first name and last name as arguments.
  5. The function prints the desired message, which includes the formatted full name.

If you find anything wrong in this Solution, feel free to reach us in the comment section.

Sharing Is Caring:

Leave a Comment