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

Respuesta :

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))

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}}