python - (beginner) the code cannot run, please give me some guidance, thank you!
伊谢尔伦
伊谢尔伦 2017-06-22 11:52:04
0
4
884

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("游戏结束,不玩啦^-^")

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(4)
学霸
# -*- 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)

女神的闺蜜爱上我

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("游戏结束,不玩啦^-^")
曾经蜡笔没有小新
  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

伊谢尔伦
# -*- 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:

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template