Python 3 Print() Function
Im trying to get an exercise from a python 2 book to work in python 3. 1 def printMultiples(n): 2 i = 1 3 while i <= 6: 4 print(n*i, '/t',) 5 i = i + 1 6 prin
Solution 1:
I assume you are trying to print a tab separated list of values, to change the code to work in Python 3 use the following function:
defprintMultiples(n):
i = 1while i <= 6:
print(n*i, end='\t')
i = i + 1print()
The print statement in Python 3 has the following signature:
print(*args, sep=' ', end='\n', file=None)
To change the end of line character in Python 3 similar to putting a comma at the end of the print statement in previous versions of Python is to use the end keyword.
Solution 2:
I'm not sure what do you want from the last line print()
defprintMultiples(n):
for i inrange(1,7):
print(n*i, '\t')
Does this work for you?
Post a Comment for "Python 3 Print() Function"