Skip to content
Advertisement

TypeError: pretty_print() takes 1 positional argument but 2 were given

PyCharm return “TypeError: pretty_print() takes 1 positional argument but 2 were given” I’ve searched for the whole night but still can’t figure it out

from IPython.display import display
from sympy import *
from sympy.interactive import printing 
printing.init_printing
t = symbols('t')
a=5
b=3
pprint(integrate(1+a/b+(a/b-1)*sinh(a*t)*sin(b*t)-(a/b+1)*cosh(a*t)*cos(b*t)+sinh(a*t)*cos(b*t)-a/b*cosh(a*t)*sin(b*t)), (t, 0, t)) 

Advertisement

Answer

In your code (t, 0, t) is the second argument to pprint (which takes only one positional argument), but it’s meant to be the second argument for integrate.

BTW, an integral from 0 to t dt seems strange as it uses the same variable for both integration and the upper bound.


You can write this in a cleaner way:

printing.init_printing() # CALL this function

t, x = symbols('t x')
a=5
b=3

# Nice readable formula for the function we're integrating
func = (
    1 + a/b + (a/b - 1) * sinh(a*t) * sin(b*t)
    - (a/b + 1) * cosh(a*t) * cos(b*t)
    + sinh(a*t) * cos(b*t)
    - a/b * cosh(a*t) * sin(b*t)
)

# Integrate `func` from 0 to some `x`
the_integral = integrate(func, (t, 0, x))

# Output the result
pprint(the_integral)

Note how putting the formula for the function in a separate variable func and the integration result into the_integral makes it harder to get lost in parentheses and pass (t, 0, t) as the argument to pprint instead of integrate.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement