Advertisement
phantom6d

ta2

Apr 20th, 2024
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. input_f = open('C:/temp/input.txt')
  2. output_f = open('C:/temp/output.txt', 'w')
  3.  
  4. def main():
  5.     line = input_f.readline() #y1
  6.     spl = line.split() #y2
  7.     op = spl[0] #y3
  8.     oper1 = spl[1] #y4
  9.     oper2 = spl[2] #y5
  10.  
  11.     err = "" #y6
  12.     res2 = "0" * 64 #y7
  13.     res = 0 #y8
  14.  
  15.     if op != "11" and op != "00": #x1
  16.         err = "001" #y9
  17.         print ("error 001: invalid operation") #y10
  18.         return
  19.  
  20.     if len(oper1) != 64 or len(oper2) != 64: #x2
  21.         err = "010" #y11
  22.         print ("error 010: invalid operand length") #y12
  23.         return
  24.  
  25.     num = set(oper1) #y13
  26.  
  27.     if num not in [{"0"}, {"1"}, {"0", "1"}]: #x3
  28.         err = "011" #y14
  29.         print ("error 011: invalid input in operand") #y15
  30.         return
  31.  
  32.     num = set(oper2) #y16
  33.  
  34.     if num not in [{"0"}, {"1"}, {"0", "1"}]: #x3
  35.         err = "011" #y14
  36.         print ("error 011: invalid input in operand") #y15
  37.         return
  38.  
  39.     if op == "11" and int(oper2, 2) == 0: #x4
  40.         err = "100" #y17
  41.         print ("error 100: dividing by zero") #y18
  42.         return
  43.  
  44.     if op == "11": #x5
  45.         res = int(oper1, 2)/int(oper2, 2) #y19
  46.     if op == "00": #x6
  47.         res = int(oper1, 2)*int(oper2, 2) #y20
  48.  
  49.     if res < -2**64 or res > 2**64: #x6
  50.         err = "101" #y21
  51.         print ("error 101: overflow") #y22
  52.         return
  53.  
  54.     res = bin(int(res)) #y23
  55.     sres = str(res)[2:].zfill(64) #y24
  56.  
  57.     output_f.write (oper1 + " " + oper2 + " " + sres) #y25
  58.  
  59. main ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement