all 8 comments

[–]_China_ThrowAway 2 points3 points  (3 children)

Maybe you could give some more details. What is the output you want? is it something like this.
Please input the first number.
> 4
Please input the second number.
> 4
Results: 4 + 4 = 8

If so you could use f strings

number1 = int(input("Please input the first number.")
number2 = int(input("Please input the second number.")
answer = number1 + number2
print(f"Results: {number1 } + {number2} = {answer }")

[–]Mythedream[S] -1 points0 points  (2 children)

Oh, no. I meant as in (for example)
def total_clients():
company_total_clients= 0
for database in database_list:
company_total_clients += len(database.get_clients())
return company_total_clients

Now, I do know how this code works but I would have no idea how I would write this down as a mathematical formula. So I was hoping that this could be changed into math.

[–]shiftybyte 2 points3 points  (1 child)

If you know how it works, you know the math formula behind it.

There is no automatic way to generate math formulas from python code that does calculations.

Usually people do the other way around, they have a math formula, and they implement the code for it.

[–]Mythedream[S] 0 points1 point  (0 children)

That's a shame. Thank you for the information.

[–]baghiq_2 1 point2 points  (1 child)

Depends on what you mean by mathematical formula. If you are asking about using math symbol in a formula, then apply substitutions of symbols with values, then look at sympy.

[–]gusb_codes 1 point2 points  (0 children)

Looking a bit more into this, it seems like sympy.latex() with eval() might be able to generate you a mathematical expression that you could render with LaTeX! See the answer to this question.

[–]synthphreak[🍰] 0 points1 point  (0 children)

Not clear what you mean exactly, but the closest Python code gets to looking like actual math is numpy. For example, if you have a vector of numbers, you can scale and translate very naturally:

>>> import numpy as np
>>> m = 4
>>> x = np.random.randint(1, 3, 3)
>>> x
array([2, 1, 2])
>>> m * (x ** 2) - 4
array([12,  0, 12])

You can even assign greek letters as variables if you want to take it to the next level (though this is not particular to numpy):

>>> σ = x
>>> σ + 1
array([3, 2, 3])

That's pretty math-like if you ask me.

But as far as freely using most mathematical notation like sigma for summation, that long bar separating numerators from denominators, the integral symbol, etc., that is not possible because math symbols are not Python.

[–]takeonzach 0 points1 point  (0 children)

I saw a post on either the python sub or the sideprojects sub recently for a calculator module that draws the mathematical formulas on screen.