[Tutor] err in integration

Msd De mmssdd1920 at gmail.com
Sat May 1 03:19:44 EDT 2021


Dear Sir,
Thank you for your email

I tried this :
print("The numerical result is {J1} (+-{err})".format(J1=J1, err=err))
o/p is :
The numerical result is 0.203920669888 (+-None)
I would like it print number in place of +-None
Thanks

On Sat, May 1, 2021 at 12:30 PM Cameron Simpson <cs at cskk.id.au> wrote:

> 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>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list