21,571 views
9 votes
9 votes
Write a program that read two integers and display their MOD,VID and their floating-point division in both settings x/y and y/x

e.g 5/3 and 3/5

User Mrkschan
by
3.1k points

1 Answer

24 votes
24 votes

Answer:

#!/usr/bin/env python

def calculate(x, y):

return {

"MOD": x % y,

"DIV": x/y, # you mean div instead of “VID”, right?

"floating-point division": float(x)/y,

}

def calculateInBothSettings(x, y):

return {

"x/y": calculate(x, y),

"y/x": calculate(y, x),

}

if __name__ == "__main__":

x = int(input("x: "))

y = int(input("y: "))

print(calculateInBothSettings(x, y))

Step-by-step explanation:

I wrote a python script. Example output:

x: 2

y: 3

{'x/y': {'MOD': 2, 'DIV': 0.6666666666666666, 'floating-point division': 0.6666666666666666}, 'y/x': {'MOD': 1, 'DIV': 1.5, 'floating-point division': 1.5}}

User Imsrch
by
2.9k points