Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in print statment
#1
#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?
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Print Error DaveG 1 1,062 Apr-07-2022, 03:10 AM
Last Post: deanhystad
  If statment Saying text is not defined KieranPage 3 2,031 Jul-20-2020, 07:03 PM
Last Post: deanhystad
  Error with print and return commands TheDark_Knight 2 1,894 Jan-15-2020, 04:59 PM
Last Post: TheDark_Knight
  Pylint Statment Count Shangeetha 1 2,005 Dec-22-2019, 04:58 PM
Last Post: Larz60+
  I am getting an Error, and not sure why? My goal is to print out rahulne22 7 2,978 Dec-01-2019, 03:53 PM
Last Post: snippsat
  Why do i have invalid syntax on a line after print, i see no error ? iofhua 5 2,876 May-24-2019, 05:42 PM
Last Post: Yoriz
  Need help with print error newbiepy 2 2,045 Apr-22-2019, 08:00 PM
Last Post: Yoriz
  Attribute error print statement error jamshaid1997 1 2,427 Jan-20-2019, 04:02 PM
Last Post: ichabod801
  Only one of two lines print/syntax error naysjp 2 3,685 Jan-12-2017, 07:08 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020