```python
# Setup
from IPython.display import Markdown, Latex, Math

import sympy
from sympy import pi

# Print units using abbreviations: 'm' instead of 'meter'
sympy.printing.str.StrPrinter._default_settings['abbrev'] = True
```


```python
# INPUTS
from sympy.physics.units import meter, foot, convert_to

input_d_value = 11.1
input_d_unit = foot
input_d_sigfigs = 3

# DESIRED UNITS
# If the input doesn't match this then a conversion will occur
desired_length_unit = meter
```


```python
# Symbol setup and unit conversion
input_d = input_d_value * input_d_unit
sigfigs = input_d_sigfigs

# unit conversion
if input_d_unit != desired_length_unit:
    converted_d = convert_to(input_d, desired_length_unit).n(input_d_sigfigs)
    conversion_latex = Math("d={original}={converted}".format(
        original=sympy.latex(input_d.n(input_d_sigfigs)),
        converted=sympy.latex(converted_d.n(input_d_sigfigs))))
    input_d = converted_d
else:
    conversion_latex=None

d_latex = Math("d={}".format(sympy.latex(input_d.n(input_d_sigfigs))))
```

## Inputs

Circle diameter:

{{ conversion_latex if conversion_latex else d_latex }}

## Area


```python
# Area formula by building expression explicitly
d = sympy.Symbol('d')
area_formula = pi*(d/2)**2

# Substitute values without simplifying
with sympy.evaluate(False):
    area_formula_sub = area_formula.subs(d, input_d)

# Compute answer
area = area_formula_sub.evalf(sigfigs)

# Output the result as an aligned equation.
# The asterisk in `\begin{align*}` tells Latex to not add an equation number on the right hand side.
# Note that str.format() uses curly braces for formatting, so any curly braces that are not part
# of a string replacement must be doubled. Hence `\begin{{align*}}` instead of `\begin{align*}`.
area_block = Latex(r"""
\begin{{align*}}
A & = {area_formula} \\
  & = {area_formula_sub} \\
  & = {area_value}
\end{{align*}}
""".format(area_formula=sympy.latex(area_formula),
           area_formula_sub=sympy.latex(area_formula_sub),
           area_value=sympy.latex(area)))
```

The area of a circle with diameter {{ d_latex }} is:

{{ area_block }}

## Circumference


```python
# circumference formula by using sympify() and displayed all on one line
circ_formula = sympy.sympify("pi*d")

# Substitute values without simplifying
with sympy.evaluate(False):
    circ_formula_sub = circ_formula.subs(d, input_d)

# Compute answer
circ = circ_formula_sub.evalf(sigfigs)

# Simple one-line equation. In regular Markdown this can be done with $$ equation $$ syntax. However,
# Latex formatting currently cannot be done inline in a Markdown cell because of evaluation order issues when
# Latex and Python-markdown Jupyter extensions are used together.
circ_formula_latex = Markdown("$$ C = " + sympy.latex(circ_formula) +
                              " = " + sympy.latex(circ_formula_sub) +
                              " = " + sympy.latex(circ) + "$$")

```

The circumference of a circle with diameter {{ d_latex }} is:

{{ circ_formula_latex }}



```python

```

2aa48938c2e95013bb0cea2e39eb57b86b2b0b55
ipynb
Jupyter Notebook
notebooks/Circle with Units and Sigfigs - SymPy version.ipynb
alugowski/jupyter-forchaps
c46904286df8b60a8e5200e0c8b6bafca3379c9d
BSD-2-Clause
2020-02-12T11:25:37.000Z
2020-02-12T11:25:37.000Z
notebooks/Circle with Units and Sigfigs - SymPy version.ipynb
alugowski/jupyter-forchaps
c46904286df8b60a8e5200e0c8b6bafca3379c9d
BSD-2-Clause
notebooks/Circle with Units and Sigfigs - SymPy version.ipynb
alugowski/jupyter-forchaps
c46904286df8b60a8e5200e0c8b6bafca3379c9d
BSD-2-Clause
Qwen/Qwen-72B
1. YES
2. YES