In: Computer Science
Write a Python program called arecongruent.py that
determines whether two integers a and b are congruent modulo n.
Your code must
work as follows: From the command prompt the user runs the program
by typing
python arecongruent.py and then your program interface prompts the
user for
the values of a, b, and n. The program outputs either True or
False, and the values
of a mod n and b mod n. Submit your Python source code
arecongruent.py.
NOTE: please include step by steps and the full python screenshots.
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.
#code
def main():
#reading a as an integer
a = int(input("Enter value for a:
"))
# reading b as an integer
b = int(input("Enter value for b:
"))
# reading n as an integer
n = int(input("Enter value for n:
"))
# displaying if a and b are congruent modulo
n, this is True if a and b
#both returns same remainder when divided by
n
if a % n == b % n:
print(True)
else:
print(False)
#displaying values of a mod n and b mod
n
print("a mod n:", a %
n)
print("b mod n:", b % n)
#calling main()
main()
#end of code
#output
Enter value for a: 8
Enter value for b: 3
Enter value for n: 5
True
a mod n: 3
b mod n: 3
#output (another run)
Enter value for a: 15
Enter value for b: 4
Enter value for n: 3
False
a mod n: 0
b mod n: 1