-
Notifications
You must be signed in to change notification settings - Fork 23
/
divmod.py
30 lines (27 loc) · 1.05 KB
/
divmod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
################################################################################
#
# Program: divmod() Function
#
# Description: Examples of using the divmod() function in Python.
#
# YouTube Lesson: https://www.youtube.com/watch?v=7xoHgWW67-g
#
# Author: Kevin Browne @ https://portfoliocourses.com
#
################################################################################
# divmod() will return both the quotient and the remainder of a division
# operation as a tuple... here quotient will be set to 3, and remainder will be
# set to 1
quotient, remainder = divmod(10,3)
print("quotient:", quotient)
print("remainder:", remainder)
# If one of the arguments to divmod() is a floating-point number the quotient
# and remainder will be floating-point numbers.
quotient, remainder = divmod(13,2.5)
print("quotient:", quotient)
print("remainder:", remainder)
# As usual with division, we cannot divide by zero, we will get the
# ZeroDivisionError as a result if we try.
quotient, remainder = divmod(13,0)
print("quotient:", quotient)
print("remainder:", remainder)