Home 04. Python Division
Post
Cancel

04. Python Division

Problem: Python Division

Solution 1: Using print() function

1
2
3
4
5
if __name__ == '__main__':
    a = int(input())
    b = int(input())
    print(a//b)
    print(a/b)

Solution 2: Using f-string

1
2
3
4
if __name__ == '__main__':
    a = int(input())
    b = int(input())
    print(f'{a//b}\n{a/b}')

Solution 3: Using format()

1
2
3
4
if __name__ == '__main__':
    a = int(input())
    b = int(input())
    print('{}\n{}'.format((a//b),(a/b)))

Solution 4: Using sep parameter

1
2
3
4
if __name__ == '__main__':
    a = int(input())
    b = int(input())
    print(a//b, a/b, sep='\n')

Solution 5: Using round() function

1
2
3
4
5
if __name__ == '__main__':
    a = int(input())
    b = int(input())
    print(round(a/b))
    print(round(a/b, 6))
This post is licensed under CC BY 4.0 by the author.

03. Arithmetic Operators

05. Loops