[Tutor] help

Alan Gauld alan.gauld at yahoo.co.uk
Wed Feb 7 18:55:35 EST 2018


On 07/02/18 21:34, Frank Dominguez wrote:

> this is my first time using python and i just cannot figure out what I am
> doing wrong im sure the answer is very simple but sadly i do not know what

Please always include full error messages in your mail
 - don't assume we will willingly run buggy code!

Also post the code in the email, using plain text rather
than attaching it. It makes replies easier and ensures
it doesn't get lost in the archives.

Here is yours with my comments:

> length = eval(input("Enter the length of the yard")
> width = eval(input("Enter the width of the yard")
> sod = eval(input("Enter the cost of sod"

You are missing a closing paren there.
But you are also missing a closing paren on all
the other lines. You close the input() but not
the eval()

> fence = eval(input("What is the cost of the fence")

Never, ever, combine eval() with input() it is a
recipe for disaster since a malicious user (or
a mis-typing one) can wreak havoc by typing in
malicious code that could, potentially trash
your computer. It's a very bad habit, avoid at
all costs.

Read the input and convert it explicitly using
int() or float() or whatever. Like so:

fence = float(input("What is the cost of the fence"))

It's much safer (and not much extra typing).

> area = length*width
> perimeter = length*2+width*2
> total_sod = area*sod
> total_fence = fence*perimeter
> landscaping = total_sod+total_fence
> print ("the total cost of landscaping is",landscaping)

This bit seems fine.

-- 
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