+ 1

Why my code doesn't work in the code Playground exercise (Python)

My function doesn't return anything even when I return a variable with the result: #taking the weight as input weight = int(input()) #complete the function def shipping_cost(weight): cost = weight * 5 return cost #function call shipping_cost(weight)

10th Oct 2023, 10:15 AM
Francisco Gutiérrez Ramos
Francisco Gutiérrez Ramos - avatar
3 Antworten
+ 7
It does return something, you're just not printing anything. Can either store the information returned and then print like this: result = shipping_cost(weight) print(result) Or just put thr function call in a print statement: print(shipping_cost(weight))
10th Oct 2023, 10:28 AM
Justice
Justice - avatar
+ 3
You need to use print on your function call like this: print(shipping_cost(weight))
10th Oct 2023, 10:27 AM
Jan
Jan - avatar
+ 2
Oh thanks guys, I didn't see I had to use the shipping_cost function as an argument of the print function. Now it makes sense, thanks a lot guys!👍🏻
10th Oct 2023, 10:32 AM
Francisco Gutiérrez Ramos
Francisco Gutiérrez Ramos - avatar