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

查看:24
本文介绍了语法错误:以“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 LEFT SINGLE QUOTATION MARK 字符,通常是您使用 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天全站免登陆