Hi, I am fairly new at the whole programming racket and I am having trouble with an assignment for my computer science class. I know homework help is discouraged, I read that sticky, but I'm curious if I am missing a fairly simple mistake.
The assignment is to make a program that takes input for a numerator and a denominator of a rational number and then divides that rational number to a certain amount of decimal places. Basically it does long division and multiplies the remainder by 10 a certain number of times specified by the user. So if the user enters 22, 7, and 20 it should print out 3.14...up to 20 digits of the rational number. My code's behavior is simply 3.1111... though.
Here is my code so far (and I am pretty sketchy with the modulo operator %; so I think I have done something wrong with it.)
def rationalnum(n, d, num_iterations):
A = n/d
B = n%d
print A
print '.'
for n in range(num_iterations):
n = B*10
c=n/d
n=n%d
print c
def main():
num = input('Please Enter a numerator to the rational number: ')
denom = input('Please Enter a denominator to the rational number: ')
num_iterations = input('Please Enter a number of decimal places to show: ')
rationalnum(num, denom, num_iterations)
main()
Any suggestions would be greatly appreciated. And I'm sorry to add another lame homework question but I am stumped.