Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Python noob and numbers
11-03-2013, 02:19 PM #1
- 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:
#!/usr/bin/python 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
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.
05-05-2014, 05:01 AM #2
- 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
Now that it is a string, you will need to change the print statement to look for a string.Code:j = "46,178,617"
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 asCode:print "It has over %s million regular user's daily." % j
Rather than a large number like you see it.Code:j = (46, 178, 617)