TOPIC

Nao sei o que fazer

Luan Guimaraes asked 1 year ago

# -*- coding: utf-8 -*-

from math import gcd

casos=int(input())

for i in range(casos):
  d=input().split()
  N1=int(d[0])
  D1=int(d[2])
  op=d[3]
  N2=int(d[4])
  D2=int(d[6])

  if op=='+':
    n=(N1*D2 + N2*D1) 
    d=(D1*D2)

  elif op=='-':
    n=(N1*D2 - N2*D1)
    d=(D1*D2)

  elif op=='*':
    n=(N1*N2)
    d=(D1*D2)

  elif op=='/':
      n=(N1*D2)
      d=(D1*N2)

  mdc=gcd(n,d)
  nr=int(n/mdc)
  dr=int(d/mdc)
  print('{}/{} = {}/{}'.format(n,d,nr,dr))

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.