Thursday, July 21, 2016

Python: Division - Hacker Rank Solution

Python: Division - Hacker Rank Solution

Task 
Read two integers and print two lines. The first line should contain integer division,  // . The second line should contain float division,  / .

You don't need to perform any rounding or formatting operations.
Input Format 
The first line contains the first integer, . The second line contains the second integer, .
Output Format 
Print the two lines as described above.
Sample Input
4
3
sample Output
1
1.3333333333333333

Python: Division - Hacker Rank Solution

Problem Tester's code :
Python 2
from __future__ import division
a = int(raw_input())
b = int(raw_input())

print a // b
print a / b
Python 3
a = int(input())
b = int(input())

print(a // b)
print(a / b)

6 comments:

  1. a =int(input(' integer a :'))
    b =int(input(' integer b :'))
    c = a/b
    print(int(c))
    print(float(c))
    what is the wrong with this code??

    ReplyDelete
    Replies
    1. it is too lengthy and they have specified to use a and b only

      Delete
  2. nothing wrong but you are using a extra variable

    ReplyDelete
  3. What is wrong with this code
    a = int(input())
    b = int(input())

    print (int(a // b))
    print (float(a / b))

    ReplyDelete
    Replies
    1. you need not required to write int and float in that print statement.

      Delete

Powered by Blogger.