User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 402,056 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,342 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 302 | Replies: 8 | Solved
Reply
Join Date: Jun 2008
Location: Fort Lauderdale - Florida
Posts: 19
Reputation: Scuppery is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Scuppery's Avatar
Scuppery Scuppery is offline Offline
Newbie Poster

subscript and superscript help!

  #1  
Jul 8th, 2008
Hey there everyone I need a little help. Right now I am in the process of writing a program that uses subscripts and superscript but I dont have a clue how to get them. I am not even sure if they can be used in python so if any of you could give me a little help I would love it.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Location: India
Posts: 271
Reputation: Agni is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 36
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Whiz in Training

Re: subscript and superscript help!

  #2  
Jul 9th, 2008
You need to give more info dude. As far as usage is concerned just look into any python tutorial on WWW
thanks
-chandra
Reply With Quote  
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,425
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 9
Solved Threads: 173
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
Kickbutt Moderator

Re: subscript and superscript help!

  #3  
Jul 9th, 2008
XML handles subscripts and superscripts amongst other things. Look into the module PyXML or wxPython's Fancytext widget.

For a fancytext example see:
http://www.daniweb.com/forums/post643697-23.html

Another way would be to use the richedit format, again wxPython's TextCtrl() widget can handle that.
Last edited by vegaseat : Jul 9th, 2008 at 10:22 am. Reason: example url
May 'the Google' be with you!
Reply With Quote  
Join Date: Jul 2008
Location: Durham, NC
Posts: 139
Reputation: jlm699 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 21
jlm699's Avatar
jlm699 jlm699 is offline Offline
Junior Poster

Re: subscript and superscript help!

  #4  
Jul 9th, 2008
For superscript you could use:
  1. >>> print '\xb2'
  2. ²
  3. >>> print '\xb3'
  4. ³
I'm not so sure about subscript though. Just try typing into your interpreter:
  1. >>> a = '<your_character_here>'
  2. >>> a
  3. '\<escaped_version_of_your_character>'
Reply With Quote  
Join Date: Jun 2008
Location: Fort Lauderdale - Florida
Posts: 19
Reputation: Scuppery is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Scuppery's Avatar
Scuppery Scuppery is offline Offline
Newbie Poster

Re: subscript and superscript help!

  #5  
Jul 9th, 2008
Ok here is my problem more detailed. Lets say I am making a simple program in which I ask the person to type in a number and that number is multiplied my some other number of my choice. Now what I want is to put a subscript or superscript to the new number. How do I do that? Here is an example of the code I just describe:

def N():
a = input("Please enter any number: ");
b = a * 0.00544
print b

Now what I want is that when the program prints b to print a subscript or superscript next to it. The reason I am trying to get the sub/superscripts is that whenever python does a mathematical operation such as 5 * 0.00544 it prints this 0.027200000000000002 which can be simplified as 0.0272x10^18. Hopefully this explain better my little dilemma.
Last edited by Scuppery : Jul 9th, 2008 at 1:41 pm.
Reply With Quote  
Join Date: Jul 2008
Location: Durham, NC
Posts: 139
Reputation: jlm699 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 21
jlm699's Avatar
jlm699 jlm699 is offline Offline
Junior Poster

Re: subscript and superscript help!

  #6  
Jul 9th, 2008
You are mistaking sub/superscript for scientific/exponential notation (P.S. your scientific notation conversion is way off).

  1. >>> '%e' % (5 * 0.00544)
  2. '2.720000e-002'
  3. >>> '%.2e' % (5 * 0.00544)
  4. '2.72e-002'
  5. >>>
That illustrates some text formatting in Python. If you'd like information check out this page on Formatting
Let's Go Pens!
Reply With Quote  
Join Date: Jun 2008
Location: Fort Lauderdale - Florida
Posts: 19
Reputation: Scuppery is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Scuppery's Avatar
Scuppery Scuppery is offline Offline
Newbie Poster

Re: subscript and superscript help!

  #7  
Jul 9th, 2008
thanks that really helped a lot I can finish my program now. BTW my the scientific notation conversion is right since there are 18 numbers after the decimal.
Reply With Quote  
Join Date: Jul 2008
Location: Durham, NC
Posts: 139
Reputation: jlm699 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 21
jlm699's Avatar
jlm699 jlm699 is offline Offline
Junior Poster

Re: subscript and superscript help!

  #8  
Jul 9th, 2008
  1. >>> '%e' % (5 * 0.00544)
  2. '2.720000e-002'
  3. >>> '%.2e' % (5 * 0.00544) ## This is the correct form of sci. notation *10^-2
  4. '2.72e-002'
  5. >>>
  6. >>> 0.0272 * 10**18 ## This is what your number was
  7. 27200000000000000.0

You see? Like I said, you were way off. That last one is 10^18
Let's Go Pens!
Reply With Quote  
Join Date: Jul 2006
Posts: 562
Reputation: jrcagle is on a distinguished road 
Rep Power: 4
Solved Threads: 72
jrcagle jrcagle is offline Offline
Posting Pro

Re: subscript and superscript help!

  #9  
Jul 9th, 2008
Good news: the convention for scientific notation

2.72e-2 (which is the correct rendering)

is so well-recognized that superscripting is not required.

Jeff
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 12:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC