我知道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 fucking 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轉換器那裏。
感謝您的幫助
使用'印刷(R) – kev