This assignment requires one file named program10.py containing a main function,
ID: 671165 • Letter: T
Question
This assignment requires one file named program10.py containing a main function, and a recursive function named findmod. Please write in python 3.0 and include sample output via screenshots if possible
The findmod function should compute a mod b but without using the % operator.
In main:
prompt the user to enter two positive integers.
call the findmod function with these integers as arguments.
print its returned value.
The findmod function, findmod(integer1, integer2), must recursively calculate the remainder and then return it.
SAMPLE OUTPUT
Enter a positive integer 17
Enter another positive integer 5
The remainder is 2
SAMPLE OUTPUT
Enter a positive integer 30
Enter another positive integer 8
The remainder is 6
Please write in python 3.0 and include sample output via screenshots if possible. This should not require third party libraries or repositories such as ent
Explanation / Answer
class ModWithoutModulo:
def findmod(self,integer1, integer2):
while integer1 >= integer2:
integer1=integer1-integer2
print integer1
p=ModWithoutModulo()
print "Enter First Integer:",
integer1 = int(raw_input())
print "Enter Second Integer:",
integer2 = int(raw_input())
p.findmod(integer1,integer2)
Hi, attached is the program . Please be careful about indentations as python works on the same scenario. This is and example working for integer values, please provide with interger inputs only, or else exception would be thrown. In case you want to handle such exceptions, surround the code with try and except :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.