2017-08-14 12 views
0

私はpythonでプログラムを作成することを目指しています。これはユーザーが1メートルあたりのフェンシングのコスト、パドックの長さと幅を入力できるようにするもので、プログラムは境界を計算して印刷する必要があります。見積価格。私はいくつかの問題に遭遇し、Stack Overflowに関する私の研究は残念ながら失敗しました。次のように私のコードはフェンシング計算プログラムのエラー

from turtle import* 
print ("Welcome to the fencing quote calculator") 
print ("In this program, you will be able to input the size of the padock as well as the cost of the fence per meter") 
again = "" 
perMetre = input(str(("Please input the cost per metre in numbers without a dollar sign") 
width = input("Please input the width of the paddock in metres") 
length = input("Please input the length of the paddock in metres") 

perimeter = (width+2) 
print ("The perimeter of this paddock is",perimeter) 
cost = int((perimeter)*(perMetre)) 
print("{:.2f}".format(cost)) 

(私は初心者です念頭に置いておく)でエラーがTypeError例外です:暗黙のうちに、エラーコードをstrをするには 'int型のオブジェクトを変換できません。 もしこれを非常に簡単な言葉で説明できたら、私は本当にそれを感謝します。 ありがとう:)

+1

'width ='文に2つの右括弧がありません。 – Prune

+0

'perMetre'はintegerまたはfloatに変換する必要があります。 「幅」も同じです。つまり、Python 3を使用している場合です。 –

答えて

0

下記の置き換えコードでコメントを参照してください。

from turtle import* 
print ("Welcome to the fencing quote calculator") 
print ("In this program, you will be able to input the size of the padock as well as the cost of the fence per meter") 
again = "" 
perMetre = input(str(("Please input the cost per metre in numbers without a dollar sign") 
width = input("Please input the width of the paddock in metres") 
length = input("Please input the length of the paddock in metres") 

# need to convert "numbers" currently input as strings to floating point numbers 
perMetre = float(perMetre) 
width = float(width) 
length = float(length) 

# also fix perimeter equation? 
#perimeter = (width+2) 
perimeter = (width + length) * 2.0 
print ("The perimeter of this paddock is",perimeter) 
cost = perimeter * perMetre 
print("{:.2f}".format(cost)) 
+0

皆さん、ありがとうございました。すべて今働いている。これからもいい結果を出し続けてください :) –