Python Data Types
This challenge was supposed to be about the different data types, however, it was about learning something new for me. Not about dtypes but about how to read stdin from python. Thankfully, u0b34a0f6ae, had the answer of using fileinput.
- Declare 3 variables: one of type int, one of type double, and one of type String. Easy Enough.
# Declaring int, float, string. i = 4 d = 4.0 s = 'HackerRank'
- Read 3 lines of input from stdin (according to the sequence given in the Input Format section below) and initialize your variables. This was the tricky part, but got it after some quick research.
# Import import fileinput ... # Initialize items as fileinput object items = fileinput.input() # Declaring input int, float, string. ii = items dd = items ss = items
- Use the + operator to perform the following operations:
- Print the sum of plus your int variable on a new line.
- Print the sum of plus your double variable to a scale of one decimal place on a new line.
- Concatenate with the string you read as input and print the result on a new line.
# Sum of ints print(i + ii) # Sum of floats print(d + dd) # Concatenation of strings print(ss + s)
- Learned a new module,
- Had fun.
- Good practice.