[Tutor] help with and
alan.gauld at yahoo.co.uk
Wed Mar 1 04:29:04 EST 2017
On 01/03/17 06:21, darrickbledsoe at gmail.com wrote:
> wage = eval(input("Enter in the employees hourly wage: ")) #get wage
> hours_worked = eval(input("Enter in the number of hours worked: "))
Don't use eval() like this it is a security risk
and is a very bad habit to get into. Instead use
an explicit type conversion such as int() or float().
> pay = wage * hours_worked # calculate pay
> ot = ((hours_worked - 40 ) * (1.5) * wage) + (wage * 40)
> double = ((hours_worked - 40 ) * (2) * wage) + (wage * 40)
You don't need all those parentheses around the terms,
especially the numbers.
> if (hours_worked <= 40):
> print (pay)
> if (hours_worked > 40 and < 60):
> print (ot)
Python sees this as:
if (hours_worked > 40) and (< 60):
And doesn't know what is intended to be less than 60.
You need to be explicit:
if hours_worked > 40 and hours_worked < 60:
You can also write what you intend in a slightly
if (40 < hours_worked < 60):
The second form an unusual style that I've only
ever seen in Python, most languages insist you
use the first version.
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor