# File: multiple_return1.py # # A program that demonstrates how to return multiple # values from a function in Python. # # In other programming languages, reference parameters # are needed so a function can return more than one # value. This is unnecessary in Python, because it # is easy to just return more than one value. # # Converts total_minutes to number of # hours and number of minutes. # def convert(total_minutes): hours = total_minutes // 60 minutes = total_minutes % 60 return (hours, minutes) n = 150 (h,m) = convert(n) print(n, "minutes =", h, "hours and ", m, "minutes") n = 180 (h,m) = convert(n) print(n, "minutes =", h, "hours and ", m, "minutes") n = 2450 (h,m) = convert(n) print(n, "minutes =", h, "hours and ", m, "minutes") ''' Output from the program: 150 minutes = 2 hours and 30 minutes 180 minutes = 3 hours and 0 minutes 2450 minutes = 40 hours and 50 minutes '''