[Tutor] combine string and integer

Terje Johan Abrahamsen terjeja@hotmail.com
Wed, 22 May 2002 20:58:31 +0000


I have two variables that I want to merge into one based on a condition:

    def amount(self):
        if amount > 0:
            amount = amount
        else:
            amount = amount, '-'
(or amount = amount * (-1), '-')

If the variable amount is a negative number, for example -25, I want this 
function to remove the - in front of 25, and put it behind it, 25-.
I assume amount[1:9] can remove the - in front? Or does the slice notation 
only work on strings? Otherways I could do the following amount*(-1)? 
However, the main problem is to get the - to go behind the amount. I have 
tried amount + "-", amount & "-" and amount, "-" as well as '-'. However, 
the two first gives me an errormessage. (unnsupported operand for float and 
string) The last one gives me this result:       (-25.0, '-') A list I 
suppose? However, I want 25- or 25.0-. It doesn't really matter if it 
becomes a string or an integer. I am going to paste it into a different 
program....

Thanks in advance,
Terje

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com