语法错误:以'\ x91'开头的非UTF-8代码 [英] SyntaxError: Non-UTF-8 code starting with '\x91'

查看:96
本文介绍了语法错误:以'\ x91'开头的非UTF-8代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为一个类编写二进制搜索程序,并且我很确定自己的逻辑是正确的,但是我一直收到非UTF-8错误.我从未见过此错误,任何帮助/说明都将是非常棒的!谢谢你.

I am trying to write a binary search program for a class, and I am pretty sure that my logic is right, but I keep getting a non-UTF-8 error. I have never seen this error and any help/clarification would be great! Thanks a bunch.

这是代码.

def main():


    str names = [‘Ava Fischer’, ‘Bob White’, ‘Chris Rich’, ‘Danielle Porter’, ‘Gordon Pike’, ‘Hannah Beauregard’, ‘Matt Hoyle’, ‘Ross Harrison’, ‘Sasha Ricci’, ‘Xavier Adams’]

    binarySearch(names, input(str("Please Enter a Name.")))

    print("That name is at position "+position)


def binarySearch(array, searchedValue):

    begin = 0 
    end = len(array) - 1 
    position = -1 
    found = False

    while !=found & begin<=end:
        middle=(begin+end)/2

        if array[middle]== searchedValue:
            found=True 
            position = middle
        elif array[middle] >value:
            end=middle-1
        else:
            first =middle+1
return position

推荐答案

您的编辑器将'(ASCII 39)替换为 U + 2018左单引号字符,通常是您使用Word或类似字处理器而不是纯文本编辑器的符号;文字处理器会尝试使您的文字更漂亮",并自动将诸如简单引号等内容替换为精美的引号.然后将其保存在 Windows 1252代码页编码中,在其中引用被保存为十六进制91个字符.

Your editor replaced ' (ASCII 39) with U+2018 LEFT SINGLE QUOTATION MARK characters, usually a sign you used Word or a similar wordprocessor instead of a plain text editor; a word processor tries to make your text 'prettier' and auto-replaces things like simple quotes with fancy ones. This was then saved in the Windows 1252 codepage encoding, where the fancy quotes were saved as hex 91 characters.

Python完全没有.它希望将源代码保存在UTF-8中,并使用'"作为引号.使用记事本,或者更好的是,使用IDLE来编辑您的Python代码.

Python is having none of it. It wants source code saved in UTF-8 and using ' or " for quotation marks. Use notepad, or better still, IDLE to edit your Python code instead.

您的代码中还有许多其他错误;例如,您不能在变量名中使用空格,而Python使用and而不是&作为布尔AND运算符. !=是需要2个操作数的运算符(表示不等于",与==相反),布尔型NOT运算符称为not.

You have numerous other errors in your code; you cannot use spaces in your variable names, for example, and Python uses and, not & as the boolean AND operator. != is an operator requiring 2 operands (it means 'not equal', the opposite of ==), the boolean NOT operator is called not.

这篇关于语法错误:以'\ x91'开头的非UTF-8代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆