sage thinks a float is a string
x = 42.44444
print("all {2:.3f} good {0} eat {1}".format("dogs","shoes",x))
ValueError: Unknown format code 'f' for object of type 'str
This is Sage in Linux Mint
x = 42.44444
print("all {2:.3f} good {0} eat {1}".format("dogs","shoes",x))
ValueError: Unknown format code 'f' for object of type 'str
This is Sage in Linux Mint
This works for me:
print("all {4:{0}.{1}} good {2} eat {3}".format(2,6,"dogs","shoes",x))
Or print("all {2:2.6} good {0} eat {1}".format("dogs","shoes",x))
This works for me:
x = float(42.44444)
print("all {2:.3f} good {0} eat {1}".format("dogs","shoes",x))
With your code, x
is not a float:
x = 42.44444
sage: type(x)
<type 'sage.rings.real_mpfr.RealLiteral'>
I guess not all aspects of Python's format are implemented for this type of object. Perhaps it passes the string representation of x
to format
, which is what leads to the error message.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2017-06-04 02:19:38 +0100
Seen: 864 times
Last updated: Jun 04 '17
BTW, why am I not getting line breaks between the x value and the print. I tried preformat and I still don't get them.
In my experience, you can't have a code block as the first thing.
Correct, that is perhaps a bug in the markdown (https://github.com/trentm/python-mark...) similar to https://github.com/trentm/python-mark... which is noted at https://askbot.org/en/question/2732/f...