search

Home  >  Q&A  >  body text

python - (beginner) the code cannot run, please give me some guidance, thank you!

The code is as follows: According to the Internet, adding #--coding:utf-8-- at the beginning will not work either

print("----------我爱鱼----------")
temp = input("不妨猜一下小甲鱼现在心里想的是哪个数字:")
if temp == "8":
    print("我曹,你是小甲鱼肚子里的蛔虫吗?!")
    print("哼,猜中了也没有奖励!")
else:
    print("猜错啦,小甲鱼现在心里想的是8!")
print("游戏结束,不玩啦^-^")

伊谢尔伦伊谢尔伦2718 days ago867

reply all(4)I'll reply

  • 欧阳克

    欧阳克2017-06-22 11:54:04

    # -*- coding: utf-8 -*-
    __author__ = 'Administrator'
    print("----------我爱鱼----------")
    temp = input("不妨猜一下小甲鱼现在心里想的是哪个数字:")
    if temp == "8":
        print("我曹,你是小甲鱼肚子里的蛔虫吗?!")
        print("哼,猜中了也没有奖励!")
    else:
        print("猜错啦,小甲鱼现在心里想的是8!")
    print("游戏结束,不玩啦^-^")

    For your question, you need to add a line of coding format in the header, which is # -- coding: utf-8 -- (add it regardless of whether there is Chinese or not)

    reply
    0
  • 女神的闺蜜爱上我

    女神的闺蜜爱上我2017-06-22 11:54:04

    It seems like your format is not correct, try my code:

    #coding: utf8
    print("----------我爱鱼----------")
    temp = input("不妨猜一下小甲鱼现在心里想的是哪个数字:")
    if temp == "8":
        print("我曹,你是小甲鱼肚子里的蛔虫吗?!")
        print("哼,猜中了也没有奖励!")
    else:
        print("猜错啦,小甲鱼现在心里想的是8!")
    print("游戏结束,不玩啦^-^")

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-22 11:54:04

    1. First of all, you need to add #--coding:utf-8--

    2. at the top of the code
    3. Secondly, the file itself needs to be stored in BOM-free UTF-8 encoding

    4. Code indentation should use spaces instead of tabs

    5. Looking at your code format, it should be Python 3 code, so it cannot be run using Python 2.x

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-06-22 11:54:04

    # -*- coding:gb2312 -*-
    print("----------我爱鱼----------")
    temp = input("不妨猜一下小甲鱼现在心里想的是哪个数字:")
    if temp == "8":
        print("我曹,你是小甲鱼肚子里的蛔虫吗?!")
        print("哼,猜中了也没有奖励!")
    else:
        print("猜错啦,小甲鱼现在心里想的是8!")
    print("游戏结束,不玩啦^-^")
    

    I added a sentence at the beginning, and then executed it and found that it can be used, without changing a word in other places.
    As shown in the picture:

    reply
    0
  • Cancelreply