Help me, what kind of function is that?



  • There are only numbers 6 and 9.

    The numbers can be "hot" - replace 6 by 9 or 9 by 6.

    Write a function that finds the maximum number that can be obtained from the reference number by "return" to a maximum of one digit.

    Implement the code as an isolated function rot(num).

    Example

    Entrance: num=9669

    Result: 9969



  • That's a much easier way:

    def rot(num):
        num = str(num)
        num = num.replace('6', '9', 1)
        return int(num)
    

    print(rot(9669))

    replace('6', '9', 1) - a function that changes 6 to 9 in line exactly 1 times. If you don't point 1 at the end, all 6 in the line will be replaced, and so it's only the first 6



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2