Challenge your Mental Math (please help me ahhhh)

Hey thanks for dropping by :smiley:

I like to practice my mental math sometimes and so I decided to make a simple terminal game which challenges you to
solve conversion and calculation problems.
I’ve still got to write the calculation problems but right now I am stuck debugging the conversion part!

If anyone would feel up to review my code and see why the conversion of hexadecimal to decimal (line 124 - 135) always says the right answer is wrong? I am pretty much dumbfounded as it literally prints for example:

“Wrong! You submitted 421321 as your final answer but the right one is: 421321”

Here is the repo, I appreciate any help!!!

I think both the hex-to-decimal and binary-to-decimal have the same issue.

You are taking the inputs and assigning them to the variable input_result. Whatever is provided as the input (text/number etc.) will be stored as a string.

In your random_conv_pick function, you are making the comparisons
input_result == result

The decimal_to_binary and decimal_to_hexadecimal return strings as result.
So, input_result == result works fine.

But, in the binary_to_decimal and hexadecimal_to_decimal functions, the result is returned as a number. Therefore, input_result == result becomes a comparison between a string and a number. Hence, the output you are seeing.

You can do either of the two:

  • Leave random_conv_pick unchanged, and modify the return to be return str(result) in the binary_to_decimal and hexadecimal_to_decimal functions.

  • Or leave the two functions unchanged and modify random_conv_pick to make the comparison input_result == str(result)