Apr-27-2019, 04:45 PM
The assignment is to: take data from input file, input file has 3 sets of columns, decimal number, L or R for left/right direction, and a rather large number for # of places to shift.
What I have done so far is to create a class to get the decimals to binary, and one to reduce the large number of rotations.
This is the hang up, anytime I write a class which needs multiple arguments, for example this one will need my binary numbers, direction and # of shifts I can never get it to accept all arguments, please help me fix this.
Sample input for program:
13327 L 1063569662
29402 R 3981203893
16801 L 3151110067
56371 R 678511388
47472 R 1431378102
60535 R 3331940147
55948 L 3564833208
36426 L 841578072
28633 L 1488402849
30434 R 528505772
What I have done so far is to create a class to get the decimals to binary, and one to reduce the large number of rotations.
This is the hang up, anytime I write a class which needs multiple arguments, for example this one will need my binary numbers, direction and # of shifts I can never get it to accept all arguments, please help me fix this.
Sample input for program:
13327 L 1063569662
29402 R 3981203893
16801 L 3151110067
56371 R 678511388
47472 R 1431378102
60535 R 3331940147
55948 L 3564833208
36426 L 841578072
28633 L 1488402849
30434 R 528505772
class dec2bin(): def __init__(self, dec): self.dec = dec def __bin__(self, dec): return bin(dec, '016b') def __str__(self): return format(self.dec, '016b') class cycles(): def __init__(self, cycle): self.cycle = cycle def __mod__(self, cycle): cycle = self.cycle // 16 return cycle def __str__(self): return str(self.cycle % 16) class bit_shift(): def __init__(self, direction, rotations): self.direction = direction self.rotations = rotations def __bit_shift__(self): for char in direction: if 'L' in char: rotated = bins << rotations else: rotated = bins >> rotations return rotated InFile = open('input.txt') for lines in InFile: lines = lines.split() dec = dec2bin(int(lines[0])) direction = lines[1] cycle = cycles(int(lines[2]))My code is probably not making sense but the first two classes do execute properly, instructor just introduced us to classes and then this assignment, i'm a bit overwhelmed by it, i understand the process of how it should work but, there's clearly a lot i'm not understanding about classes