What's your name, Tuple - HackerRank solution in python

Solution for hackerRank problems What's your name, Tuple in Python.

1. What's your name

You are given the first name 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

string: 'Hello firstname lastname! You just delved into python' where firstname and lastname 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 ≤ .

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.

Procedure :

1. Start.

2. Get first name and last name from user.

3. Create a function to perform the given operation.

4. Concatenate the first name and last name to get the desired output.

5. Call the function wherever required.

6. End

Code :

def print_full_name(first, last):

    a=first+" "+last+"!"

    print("Hello",a,"You just delved into python.")

if __name__ == '__main__':

    first_name = input()

    last_name = input()

    print_full_name(first_name, last_name)

Explanation of the python functions used :

  • + => used to concatenate string
  • print() => Prints the data
2. Tuple

Given an integer, N, and  space-separated integers as input, create a tuple,t , of
those integers. Then compute and print the result of hash(t).

Note: hash() is one of the functions in the __builtins__ module, so it need not be
imported.

Input Format

The first line contains an integer, n , denoting the number of elements in the
tuple. The second line contains n  space-separated integers describing the
elements in tuple.

Output Format

Print the result of hash(t).

Sample Input 0
2
1 2

Sample Output 0

3713081631934410656

Procedure :
1. Start.
2. Get the elements of the tuple from the user and store them in a tuple.
3. Print the hash value of the tuple.
4. End.

Code :

n=int(input())

l=list(map(int,input().split()))

t=tuple(l)

print(hash(t))

Explanation of the python functions used :
  • map()- used to apply the given function to each item of a given iterable (list, tuple).
  • split()- splits the input based on the given delimiter and returns a list. It
        defaultly takes space as the delimiter.
  • hash()- returns the hash value of an object.

Comments

Popular posts from this blog

Finding the percentage in python - HackerRank solution

HackerRank challenges with solutions (Rearrangement, Formula, Word sorting, Numbers, Sentence)

ginortS in Python - HackerRank solution