HackerRank Day 1 Solution in Python: Data Types

Today we will see the HackerRank Day 1 Solution in Python. The problem is named Data Types which is part of 30 Days of code on HackerRank. Let’s get started!

Day 1: Data Types Problem statement

We are given three variables which already been declared and initialized. The given three variables are of type int, double, and String. Our task is to declare and get input of three more variables one of type int, one of type double, and one of type String. Then we have to Print the sum of the int variable on a new line, print the sum of the double variable on a new line, and, print the concatenation of the strings on a new line.

Sample Input

12
4.0
is the best place to learn and practice coding!

Sample Output

16
8.0
HackerRank is the best place to learn and practice coding

Explanation

When we sum the integers 4 and 12, we get the integer 16. When we sum the floating-point numbers 4.0 and 12.0, we get 16.0. When we concatenate HackerRank with is the best place to learn and practice coding!, we get HackerRank is the best place to learn and practice coding!

You can solve the problem here.

HackerRank Day 1 Solution in Python

#Initialize integer, double, and String variables.
i = 4
d = 4.0
s = 'HackerRank '

# Read and store an integer, double, and String to variables.
input_int=int(input())
input_float=float(input())
input_str=str(input())

# Print the sum of both integer variables on a new line.
print(i+input_int)
# Print the sum of the double variables on a new line.
print(d+input_float)
# Concatenate and print the String variables on a new line
print(s+input_str)

Code Explanation

  • First, we read and store an integer, double, and String to the variables as input_int, input_double, and input_string
  • Then, we print the sum of both integer variables on a new line and print the sum of the double variables on a new line.
  • Finally, concatenate and print the String variables on a new line

Also Read:

Share:

Author: Keerthana Buvaneshwaran