Python Forum
Why am I getting this error?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why am I getting this error?
#1
please give a runnable sample of your code with the full error text or a clear description of the problem

WHY AM I GETTING THIS ERROR
    def adding_report(report = "T"):
        while True:
            integer = input("Input an integer to add to the total or 'Q' to quit: ")
            total = 0
            total = total + integer
        
            if integer.isdigit():
                if report == "A":
                    str(print("Items"\n\n, integer))
                    break
                elif report == "T":
                    print(total)
                    break
            elif integer.startswith().lower("Q"):
                break
            else:
                print("Input is invalid")
        return report

    adding_report("A")
File "<ipython-input-1-93d20aaf6069>", line 10
str(print("Items"\n\n, integer))
^
SyntaxError: unexpected character after line continuation character
#2
Simple answer - because you have \n\n after the closing " of string Items on line 9.
\ at the end of the line is used to indicates that the logical line is continued on the following physical line (after whitespace). In your case your code continues on the same line...
line#9 should be
str(print("Items\n\n", integer))
#3
Well, print() function returns None so I can't guess why you are passing it as an argument to str()...
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
#4
oh, didn't notice this... Of course wavic is right
 
print("Items\n\n", integer)
#5
I'm locking this thread as a duplicate.  Please don't post the same thing multiple times.


Forum Jump:

User Panel Messages

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