可能重复:
使用 Python 3 打印时出现语法错误
我知道 Python 应该是解释语言之神……它的简单性,没有冗余,等等等等。但由于我太习惯于 C、C++、Java、Javascript 和 Php,我必须承认这很烦人。这是我的代码:
#!/usr/bin/python3.1
def shit(texture, weight):
if textura is "green":
texturaTxt = "Shit is green"
elif textura is "blue":
texturaTxt = "Shit is blue"
elif textura is "purple":
texturaTxt = "Shit is purple"
else:
print "Incorrect color"
break
if weight < 20:
pesoTxt = " and weights so few"
elif weight >= 20 and peso <=50:
pesoTxt = " and weights mid"
elif weight > 50:
pesoTxt = " and weights a damn lot"
else:
print "Incorrect weight"
return texturaTxt + pesoTxt
c = input("Introduce crappy color: ")
e = input("Introduce stupid weight: ")
r = shit(c, w)
print r
我正在尝试学习 Python,而我想要实现的是:
...
function shit(texture, weight) {
string textureTxt = "Shit is ", pesoTxt = " and weights ";
switch(texture) {
case "green": textureTxt .= "green as an applee"; break;
case "blue": textureTxt .= "blue as the sky"; break;
case "purple": textureTxt .= "purple as Barny"; break;
default: cout<<"Incorrect texture, try again later" <<endl; exit;
}
//etc
}
string color = "";
int weight = 0;
cout<<"Introduce color: ";
cin>>color;
//etc
cout<<shit(color, weight);
...
但我放弃了,我不能让它工作,它会引发我的各种错误。希望那里有一些 C++ 或 php 或 C 到 python 的转换器。
谢谢你的帮助