前提・実現したいこと
今、codacademyで、様々な配送のコスト計算と、一番安い配送方法をプログラムする課題をやっています。
3つ目のファンクションで、重量に対してどの配送方法が一番安いか調べて、その結果と共に”the cheapest shipping way is ~~ and the price is $~~!.と出したいのですが、そのreturnの文に対してエラーが出てしまいます。どこがいけないのでしょうか?
発生している問題・エラーメッセージ
TypeError: can't multiply sequence by non-int of type 'str'
該当のソースコード
python3
1def ground_shipping(weight): 2 if weight<=2.0: 3 cost=weight*1.50+20.00 4 if weight>2.0 and weight<=6.0: 5 cost=weight*3.00+20.00 6 if weight>6.0 and weight<=10.0: 7 8 cost=weight*4.00+20.00 9 if weight>10.0: 10 cost=weight*4.75+20.00 11 return cost 12 13premium_shipping=125.00 14 15def drone_shipping(weight): 16 if weight<=2.0: 17 cost=weight*4.50 18 if weight>2.0 and weight<=6.0: 19 cost=weight*9.00 20 if weight>6.0 and weight<=10.0: 21 cost=weight*12.00 22 if weight>10: 23 cost=weight*14.25 24 return cost 25 26def the_cheapest_shipping(weight): 27 28 if ground_shipping(weight)<premium_shipping and ground_shipping(weight)<drone_shipping(weight): 29 the_cheapest_way="ground shipping" 30 the_price=ground_shipping(weight) 31 if premium_shipping<ground_shipping(weight) and premium_shipping<drone_shipping(weight): 32 the_cheapest_way="premium shipping" 33 the_price=premium_shipping 34 else : 35 the_cheapest_way="drone shiipping" 36 the_price=drone_shipping(weight) 37 return ("the cheapest shipping way is "+the_cheapest_way+" and the price is $"*str(the_price)+" !.") 38 39 40 41 42print(the_cheapest_shipping(8.6))
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/20 02:27 編集
2019/04/20 02:27
2019/04/20 02:28
2019/04/20 02:33