Question: ''' Prompts the user for two strictly positive integers, numerator and denominator. Determines whether the decimal expansion of numerator / denominator is finite or infinite.
''' Prompts the user for two strictly positive integers, numerator and denominator.
Determines whether the decimal expansion of numerator / denominator is finite or infinite.
Then computes integral_part, sigma and tau such that numerator / denominator is of the form integral_part . sigma tau tau tau ... where integral_part in an integer, sigma and tau are (possibly empty) strings of digits, and sigma and tau are as short as possible. '''
import sys from math import gcd
try: numerator, denominator = input('Enter two strictly positive integers: ').split() except ValueError: print('Incorrect input, giving up.') sys.exit() try: numerator, denominator = int(numerator), int(denominator) if numerator <= 0 or denominator <= 0: raise ValueError except ValueError: print('Incorrect input, giving up.') sys.exit()
has_finite_expansion = False integral_part = 0 sigma = '' tau = ''
# Replace this comment with your code
if has_finite_expansion: print(f' {numerator} / {denominator} has a finite expansion') else: print(f' {numerator} / {denominator} has no finite expansion') if not tau: if not sigma: print(f'{numerator} / {denominator} = {integral_part}') else: print(f'{numerator} / {denominator} = {integral_part}.{sigma}') else: print(f'{numerator} / {denominator} = {integral_part}.{sigma}({tau})*')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
