# Ultra Super Calculation Calculator

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!

OK so I was having problems with my code,

and this error message comes up

Welcome to Andres’s Calculator!
Value: 5 stored in the Register: 1.
Value: 10 stored in the Register: 2.
Invalid OPCODE
Invalid OPCODE
Invalid OPCODE
Invalid OPCODE
Traceback (most recent call last):
File “calculator.py”, line 168, in
File “calculator.py”, line 129, in binary_reader
self.get_last_calculation()
File “calculator.py”, line 112, in get_last_calculation
last_value = f"Last result = {int(self.history_registers[self.temp_history_index], 2)}"
TypeError: int() can’t convert non-string with explicit base

help plz?

It seems that `int(firstArgument, 2)` requires that first argument to be a string,
but the stuff in `self.history_registers` start out being integers:
In the `__init__` function, you have `self.history_registers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]`

You can fix this by only using that `int(firstArgument, 2)` if the first argument is a string.

``````    last_value = f"Last result = {int(self.history_registers[self.temp_history_index], 2)}"
``````

you could put something like

``````   from_register = self.history_registers[self.temp_history_index]
if isinstance(from_register, str):
last_value = f"Last result = {int(from_register, 2)}"
else:
last_value = f"Last result = {from_register}"
``````

doesn’t seem to work

updated it a little

Its getting better, just need these now

Welcome to Andres’s Calculator!
The number 5 was stored to register 1
The number 10 was stored to register 2
Calculated Result: 5
Calculated Result: 5
Calculated Result: 0
Divison by 0 error: 5/0.
Calculated Result: 0
Traceback (most recent call last):
File “calculator.py”, line 175, in
File “calculator.py”, line 136, in binary_reader
self.get_last_calculation()
File “calculator.py”, line 112, in get_last_calculation
last_value = f"The last calculated value was: {int(self.history_registers[self.temp_history_index], 2)}"
TypeError: int() can’t convert non-string with explicit base

so I got this solution but I was wondering if its correct

Welcome to Andres’s Calculator!
The number 5 was stored to register 1
The number 10 was stored to register 2
Calculated Result: 5
Calculated Result: 5
Calculated Result: 0
Divison by 0 error: 5/0.
Calculated Result: 0
Last result = 0
Last result = 0
Last result = 0

found it, the store_to_register was not indented correctly

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.