[Tutor] err in integration
Cameron Simpson
cs at cskk.id.au
Sat May 1 02:59:20 EDT 2021
On 01May2021 12:07, Msd De <mmssdd1920 at gmail.com> wrote:
>Dear Sir,
>I would like to print the error in numerical calculation.
>I get this error
>*Traceback (most recent call last):*
>
>* File "DFF_test.py", line 45, in <module> print("The numerical result
>is {:J1} (+-{:err})".format(J1, err))ValueError: Invalid conversion
>specification*
You don't want the colon before the parameter names in your format
string. Text after the colon is a format specifier (eg to print the
value in a particular way), rather than what you want, which is to name
the value you want to print.
Try this:
print("The numerical result is {J1} (+-{err})".format(J1, err))
Actually, that won't work: your providing _positional_ values to
.format(). Try this:
print("The numerical result is {J1} (+-{err})".format(J1=J1, err=err))
Also, you can do this more simply with a "format string", thus:
print(f"The numerical result is {J1} (+-{err})")
which pulls the parameter values straight our of your local variables.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Tutor
mailing list