Python Forum

Full Version: Error in print statment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
#Example 2:
n = 32
guess = 0
while guess != (n**3) - 1:
	guess +=1
print("%d is equal to (%d**3)-1",%(guess,n))
Error comes up and places it at the percentage symbol %(guess, n). Can someone explain why or a better way to output variables guess and n?
1. in python3 print is function, not statement
2. line #6 should be
print("%d is equal to (%d**3)-1" %(guess,n))
3. You use so called old-style. better use so called new-style, or in python 3.6+ - the newest f-string
print("{} is equal to ({}**3)-1".format(guess,n))
print(f"{guess} is equal to ({n}**3)-1")
some additional reading
https://pyformat.info/
https://docs.python.org/3.7/library/stri...i-language