[Tutor] How to calculate the total cost

Alan Gauld alan.gauld at btinternet.com
Wed Mar 30 19:46:12 EDT 2016


Forwarding to the list, please always use Reply All or reply List when
responding to tutor messages.

On 30/03/16 21:03, Nevina Dias wrote:
> Hey,
> I'm not sure.. 
> This is how our teacher said to do. He said to use input..

input() is the correct thing to use in v3 but you are using it wrongly.
But first please confirm whether you are using Python v2 or v3?
input() works very differently depending on which version you use.

What happens when you try to run your program as it is?
Do you get an error message?


One of the most important techniques to learn in Python is to write
small amounts of code and then test them. Only when the first
small part is working should you write more code.
Then if it breaks you know which bit of code(the new bit)
must be faulty.

So before worrying about totals get the existing code to run
without errors.

 
>
> pizzatype = [3.50,4.20,5.20,5.80,5.60]
> drinktype = [0.90,0.80,0.90]
> topping = [0.50,0.50,0.50,0.50]
>
> def Total_cost_cal (pt ,dt ,t):
>     total = pt + dt + t
>     return total
>
> but it didn't work.
>

That code doesn't do anything. You just define some values
but never use them. But saying "it didn't work" is not helpful.
It doesn't tell us how it didn't work. Did you get an error
message? If so what? If not did you get any output? - what?
Was it what you expected? If not what did you expect?

If you provide more detailed information you will get more
useful feedback.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list