Hexo

Home Archives
2018-05-07
Python

math.log(243,3) problem

Problem

In python:

1
2
3
4
>>> import math
>>> math.log(243,3)
4.999999999999999
# Expected: 5

Solution

  1. 1
    2
    3
    >>> import math
    >>> math.log10(243)/math.log10(3)
    5
  2. 1
    2
    3
    4
    5
    6
    7
    8
    9
    >>> import math
    >>> x = math.log(243,3)

    # Judge whether an int
    >>> judge = (round(x)-x) < 0.0000001
    True

    # get the Int value
    >>> round(x)
Share
Newer
float to int & float 精度转换
Older
ASCII ord() chr()

Categories

  • Hexo
  • Java
  • Leetcode
  • Python
  • Shell Command
  • Uncategorized
  • Web
    • Back-end
      • Django
    • Front-end
  • python

Tags

  • Bit Manipulation
  • Git
  • Set

Tag Cloud

Bit Manipulation Git Set

Archives

  • September 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018

Recent Posts

  • Leetcode 经验
  • Establish a django project
  • Set Max and Min in Python
  • Build a html page
  • HTML Basics
© 2018 John Doe
Powered by Hexo
Home Archives