有人可以用提供的代码向我解释字符串文字吗?

时间:2015-09-11 02:32:38

标签: python pycharm

为了使这个程序有效,我需要更改什么?我得到了:

line 10
SyntaxError: Non-UTF-8 code starting with '\x92' in file C:/Users/RobotAdmin/PycharmProjects/untitled3/dialouge on line 10, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

我不知道这意味着什么。

def main ():
    phrases = "Thank You Please Hello Hi How Old Are You What Is Your Address"**       # String literal

    print(phrases[17:22])   # This statement prints a specific segment of characters from the string literal
    name = input('What is your name? :')     # This statement prompts the user to enter their name and accepts it
    print(phrases[23:25] + " " + name)     # Retrieves from the string literal,and combines it with the name
    print(phrases[25:41])   # This Statement asks for the user’s age
    age = input('Age in Years? :')  # This statement prompts the user to enter their age and accepts the age the entered
    print(phrases[42:64])   # This segment asks What the user’s address is
    address = input("Street Address, City, State, Country") #This statement asks user to enter their address
    print (""
           "______________________________"
           "|                            |"
           "|",name,"                    |"
           "|                            |"
           "|",age,"                     |"
           "|                            |"
           "|",address,"                 |"
           "|                            |"
           "|                            |"
           "|____________________________|")

1 个答案:

答案 0 :(得分:-1)

首先,如果你在列表中分解你的短语而不是拼接字符串,那么可读性会更好。

phrases = ['Hello', 'Thank You', 'How old are you'] #rest of phrases    
print (phrases[0]) #prints out "Hello"

其次,我完全按照你发布的方式尝试了代码,但是插入了名称,年龄和地址的虚拟值,代码运行没有错误(尽管可能没有你可能想要的格式化) )。它所讨论的Unicode字符(' \ x92')是一个逗号。你有任何无关的逗号吗?