简体   繁体   中英

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)) 

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM