What is wrong with my code?



create a python program below that prompts the user for their hourly pay rate and the number of hours they worked for the week and computes their pay amount. Any hours worked over 40 are paid at time-and-a-half (1.5 times the normal hourly rate).

Replace this line with your code.

hours=raw_input("Enter number of hours worked:")
payrate=raw_input("Enter the hourly wage:")
extrahours = hours - 40
overtime = payrate * 1.5 * extrahours

if hours <= 40:
pay = payrate * hours
elif hours > 40:
pay = 40 * payrate + overtime
print "Invalid entry, please start over."

print "You should get paid around % dollars." %(pay)


raw_input stores as string, you might want to convert to integer (int()) or float (float()), string math sucks.

and one small detail for later: always validate user input


dumb question.... how do i go about converting my strings to the (int())?


int() is the function call you need for the conversion, so the argument provided will be converted to a integer:

print int("3")


hours=raw_input("Enter number of hours worked:")
return int(hours)
payrate=raw_input("Enter the hourly wage:")
return int(payrate)

so now that I do this the error of " File "python", line 2
SyntaxError: 'return' outside function"
keeps coming up...


why do you use return? raw_input() is also a function call, yet you stored the result of this in a variable, why can't you do the same for int()?


i got it now.. thank you very very much!!