Forums

How can i print a string and do the math at the same time?

I've been following this book called "LEARN PYTHON THE HARD WAY", but it seemed to use the python2, so when I practiced, the code on the book said like this 'print "Hens", 25+30/6', and it should turn out to be like this 'Hens 30'. But I couldn't do that on python3, or at least I don't know how, I know how to print Hens-- print('Hens'), but have no idea how to do the math.

Have a look here: http://help.pythonanywhere.com/pages/SaveAndRunPythonVersion/

Yo can those it this way:

print("Hens, %s" % (25+30/6))

or

calc = 25+30/6

print("Hens, %s" % (calc))

if you are using python 3.6 this also works:

print(f"Hens, {25+30/6}")

or

calc = 25+30/6

print(f"Hens, {calc}")