About 50 results
Open links in new tab
  1. Fractions in Python - Stack Overflow

    Jan 10, 2016 · Is there anyway to compute a fraction, e.g. 2/3 or 1/2, in Python without importing the math module? The code snippet is simple: # What is the cube root of your number n = …

  2. class - Using Fractions in Python - Stack Overflow

    Mar 10, 2013 · I'm using classes here to input a fraction (when given the numerator and denominator), as well as add and multiply two fractions together. For some reason, the imported fractions module …

  3. How to convert a decimal number into fraction? - Stack Overflow

    0 Use python built-in library sympy. if you input your fraction as string by '', any form of sympy module will convert them into rational fractions:

  4. How do I take a fraction as an input in Python, and use the fraction's ...

    Aug 24, 2020 · How generous do you want to be in accepting input? If it's just vulgar fractions (or mixed fractions), you can have a special case for that, either using .split('/') or regular expressions to break …

  5. adding two fractions in python - Stack Overflow

    Apr 3, 2015 · I am trying to add two fractions in python if input 1/4 + 1/4, I am expecting 1/2 result I built a fraction class with an __add__ method for addition from fractions import gcd class fraction: ...

  6. Python-properly adding fractions - Stack Overflow

    Dec 19, 2018 · I would like to do some calculation with fractions, keeping all the numbers as fractions and never converting to decimals. For example 1/2+1/4=3/4. We can do this in Python for example …

  7. How to simplify a fraction in Python? - Stack Overflow

    Nov 20, 2020 · 2 still learning Python so any help is welcome. I have written a funtion to get a fraction, but more often than not the fraction can be simplified. My code does not do this yet. Any ideas how …

  8. How is python's fractions.limit_denominator implemented?

    Nov 18, 2012 · The fractions module is written in Python and you can just look at the source code. It contains the following comment.

  9. Convert fraction to decimal in Python - Stack Overflow

    Since both Fraction and Decimal are objects in Python's standard library, the question in title implies you want to do this python - Best way to convert fractions.Fraction to decimal.Decimal? - Stack Overflow. …

  10. Does Python have a function to reduce fractions?

    Jul 8, 2013 · For example, when I calculate 98/42 I want to get 7/3, not 2.3333333, is there a function for that using Python or Numpy?