Cannot display output in PyCharm

While I was learning python on codecademy, the method I was tough to display variable on output was
print "SomeText: %s" % (variable)

When i try to execute same code on PyCharm it gives me an error:

from random import randint output = randint(1, 6) print('Output: %d') % output

Output: %d Traceback (most recent call last): File "C:/Users/CH325/Desktop/Python/Dice/", line 8, in <module> print('Output: %d') % output TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

Are there any other ways to display the variables? Or is my code wrong?

your last line should look like:

print('Output: %d' % output)

IMHO a better way to print it is (but its Python3-style):

print("Output: {}".format(output))
1 Like

What does format stands for?

Its a method to format strings in Python3.
Take a look at Format String Syntax for further informations.

Happy coding :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.