Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2010
    Thanked 0 Times in 0 Posts

    Python noob and numbers

    Have only just started learning Python and to practice what i have learned so far i wrote this:

    i = 'Skype'
    j = 46,178,617
    x = 'VOIP'
    Z = "Making it a market leader in it's field."
    print "%s is an online %s product." % (i, x)
    print "It has over %d million regular user's daily." % j
    print "Making %s a market leader in it's field." % i
    But when i try to run it i get the following error:

    Skype is an online VOIP product.
    Traceback (most recent call last):
    File "./more_practice.py", line 8, in <module>
    print "It has over %d million regular user's daily." % j
    TypeError: not all arguments converted during string formatting

    I am convinced that the problem is down to the variable, j = 46,178,617 because it is such a large number. So could someone tell me how i can display the contents of the variable correctly please.

  2. #2
    New Coder
    Join Date
    Mar 2009
    Thanked 2 Times in 2 Posts
    Hello Frump, You are correct, the issue is with that variable j.

    The simplest way to resolve this is to make it a string. You can do so by changing the value to
    j = "46,178,617"
    Now that it is a string, you will need to change the print statement to look for a string.
    print "It has over %s million regular user's daily." % j
    The reason it did not work without the Quotes is because the commas were making it act like a tuple with individual integers of 46, 178 and 618. So your value is the same as
    j = (46, 178, 617)
    Rather than a large number like you see it.
    The Game


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts