In else, SyntaxError: invalid character identifier appears [overlapping]

Asked 2 years ago, Updated 2 years ago, 22 views

(Two answers) 6 months ago

I use Python in Windows.

After Else, I can't help but get stuck.

I would like to print "Ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

volume=30
if volume <50:
     print("Oh, my God.")
else:
  print("I can hear you")

python

2022-09-30 19:34

1 Answers

SyntaxError, or syntax error, is often seen when there is a problem with the way the program is written.

If the program you are trying to run this time is exactly the same as the one in the questionnaire, the problem is that the symbol colon after else is full-width colon instead of half-width colon.

When I ran the questionnaire program in my environment, I got the following error:

File"/tmp/example.py", line 4
    else:
        ^
SyntaxError: invalid character ':' (U+FF1A)

As this error message indicates, Python cannot recognize the symbol immediately after else and has an error.

By the way, even if you correct this error, the space at the beginning of the line print("I can hear you") is not a half-width space but a full-width space , which results in an error.It would be good to fix this as well.


2022-09-30 19:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.