Reputation: 31
age = int(input("Please type your age:"))
if int(age) >= 18:
print("Sorry, you couldn't enter!")
else:
print("Congratulation, have a good time!")
SyntaxError: Non-UTF-8 code starting with '\xa3' in file go to.py on line 1, but no encoding declared;
Why?
Upvotes: 1
Views: 1143
Reputation: 20812
There is no text but encoded text.
If a file was written from text then the writer chose a character encoding. Communication of a text file includes the bytes and knowledge of the character encoding.
You are telling the compiler (probably by default) that your file was encoded with UTF-8. It's saying that it can't be (and it's probably correct). So, you first have to tell it which encoding it is.
On the other hand, since UTF-8 is a very common encoding for the Unicode character set and Unicode has all the characters you are likely to ever use, and it's the default for many, many programs, including Python, you could convert the file to UTF-8.
@soon's answer deals with the secondary problem of using characters for syntax that aren't part of the syntax. They are confusables.
Upvotes: 1
Reputation: 33701
Your code contains several characters unrecognizable by python interpreter. They looks like regular (
and :
:
In [8]: ord('(')
Out[8]: 40
In [9]: ord('(')
Out[9]: 65288
In [10]: ord(':')
Out[10]: 58
In [11]: ord(':')
Out[11]: 65306
It seems like you copied the code from somewhere - just manually replace all parentheses and colons with valid characters
Upvotes: 7