[Tutor] small graphics question

dn PyTutor at DancesWithMice.info
Wed Feb 10 16:23:56 EST 2021


On 10/02/2021 14.01, nathan tech wrote:
> Gosh! so sorry, I didn't realise my mail client had automatically
> switched over to the power to actually look superscript!

Unlikely that it was you - some email packages/web-page presentations
have a mind of their own!


> So, to clarify and answer questions:
> 
> 1. I do, in fact, know how to work out powers and fractions in python,
> (though thanks for the tips!) :)
> 
> 2. Yes, what I am actually asking is, how do I go about displaying
> formulae styled strings in something such as the print function.
> 
> that is to say, for instance, print("2/3") should come out as 2, with a
> line and the 3 under it.
> 
> Similarly 2 to the power of 3, should come out as 2 superscript 3.
> 
> Relatedly I need to make it variable, so the 2 superscript 3 could be 5
> superscript 293, which is why I'm not just finding the characters on
> google and substituting in.

If the result can be computed as a string (or graphic) for printing, it
can be a Python object (variable).


> I hope this helps!
> 
> Side note: I, myself, and blind and that may also contribute to why I
> didn't notice the mail client turning the characters properly and why my
> descriptions of fractions is a bit wonkey, sorry in advance :)

Which brings me to ask (apologies for nosiness): using
sub-/super-scripts and fractions, which must fit within the current
line-height, must surely be more difficult to read - so why do it (that
way)?


Extending further, a suggestion to look at Tex/Latex (which was
apparently only sent to me, cf entire list) looked likely. One reason
that package was invented (by a ComSc 'luminary' no-less!) was to enable
the printing of math formulae/formulas in traditional text-book and math
notation instead of the numerator/denominator format forced upon us by
typewriters.

However, is it possible to combine wxPython with Tex?



NB to continue to read beyond this point illustrates why top-posting is
'frowned upon' by the list, ie the logic of a question-then-answer
sequence in this type of forum


> On 09/02/2021 23:27, dn via Tutor wrote:
>> On 10/02/2021 11.36, nathan tech wrote:
>> ...
>>
>>> How do I write x to the power of y, in python/
>>>
>>> Not 5^2 for 5 squared, but 5 superscript 2? or 5 superscript x where x
>>> is any number?
>>>
>>> Similarly, how do I produce fractions??
>>>
>>> I asked here in the end because I figure for wx python it is just
>>> tracking down that character sequence and then writing it on screen
>>> (which I can do!)
>>
>> Interestingly, I started-out puzzling your question because Thunderbird
>> (email client) displayed the "Not 5..." with the power as a superscript.
>> It was only when I hit Reply that I saw the text as "Not 5 circumflex
>> 2". Can only guess what you will see (above).
>>
>> Please clarify "write" and "produce". Do you want to know:
>> - how to compute numbers raised to some power, and
>> - how to compute values expressed as numerator and denominator
>> (fractions)
>> or
>> - how to display formulae (including powers and/or fractions) as text in
>> a convenient manner
>>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

-- 
Regards,
=dn


More information about the Tutor mailing list