Skip to content

Issues with "Exercise 4: Base converter" in Control Flow notebook #330

@j-piller

Description

@j-piller

Describe the bugs
A) Final string should be reverted, with e.g. result = result[::-1], to yield the correct result.

# Convert to target base
result = ""
while decimal > 0:
digit = decimal % to_base
result += valid_digits[digit]
decimal //= to_base
return f"-{result}" if is_negative else result

        decimal //= to_base

    #TODO: result = result[::-1] to revert the string
    # Test: e.g. -"A00", from_base=16, to_base=13 (2560 in base_10) should return -121C and not -C121)

    return f"-{result}" if is_negative else result

B) In the case of to_base=10 the sign is not added.

if to_base == 10:
return str(decimal)

if to_base == 10: return str(decimal) #TODO: Handle negative numbers e.g. f'-{str(decimal)}' if is_negative else str(decimal)

To Reproduce
Steps to reproduce the behavior:
A. reference_base_converter("-A00", 16, 13)
B. reference_base_converter("-A00", 16, 10) or any negative number converted from base!=10 to base=10

Expected behavior
A: reference_base_converter("-A00", 16, 13) returns -121C [2560 in base 10]
B: reference_base_converter("-A00", 16, 10) returns -2560

Where did you run the tutorial?

  • Local installation (conda: jupyter lab)

Additional context
First GitHub reported issue, I apologize for anything unclear.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions