Converting an improper fraction to a mixed number with python
问题 I need to us python to convert an improper fraction to a mixed number or even a float to a mixed number. My code is as follows: from fractions import Fraction numerator = int(input("Enter numerator ") ) denominator = int(input("Enter denominator ") ) num = numerator / denominator num = Fraction(num) print(num) If input is 5 and 4, the output is '5/4' not a mixed number. 回答1: You can use the divide and modulo operators to print this: The integer part is numerator // denominator . The numerator