Why does this not work?

A forum for general discussion of the Python programming language.

Why does this not work?

Postby cramsteems » Thu Sep 19, 2013 5:13 pm

I need to write a program to do this, and I would like it to be done using the commands I have already used in the program but for some reason this does not want to work?

Write a program that asks the user for the number of hours worked this week and their hourly rate of
pay. The program is to calculate the gross pay.
If the number of hours worked is greater than 40, the extra hours are paid at 1.5 times the rate. The
program should display an error message if the number of hours worked is not in the range 0 to 60.

Code: Select all
print("Please enter values below:")
hours = ("Number of hours worked: ")
pay = ("Hourly rate of pay: ")
if int(hours) < 40:
    pay2 = (int(hours) * int(pay))
    print("Gross pay = ", end=""),print(pay2)
if int(hours) > 40:
        pay2 = (40 * (int(pay)) + ((int(hours) - (40)) * (int(pay)*(1.5))))
        print("Gross pay = ", end=""),print(pay2)
if int(hours) < 0:
    print("This value is too low for the range")
if int(hours) > 60:
    print("This value is above the range")
Last edited by stranac on Thu Sep 19, 2013 5:16 pm, edited 1 time in total.
Reason: Added code tags, locked post
cramsteems
 
Posts: 10
Joined: Thu Sep 19, 2013 5:11 pm

Re: Why does this not work?

Postby Yoriz » Thu Sep 19, 2013 5:20 pm

Your inputs are missing.
Code: Select all
print("Please enter values below:")
hours = input("Number of hours worked: ")
pay = input("Hourly rate of pay: ")
if int(hours) < 40:
    pay2 = (int(hours) * int(pay))
    print("Gross pay = ", end=""),print(pay2)
if int(hours) > 40:
        pay2 = (40 * (int(pay)) + ((int(hours) - (40)) * (int(pay)*(1.5))))
        print("Gross pay = ", end=""),print(pay2)
if int(hours) < 0:
    print("This value is too low for the range")
if int(hours) > 60:
    print("This value is above the range")
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 779
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Why does this not work?

Postby stranac » Thu Sep 19, 2013 5:20 pm

You're not getting the user's input at all.
You should use the input() function to do that.

There are other problems with your code, but this should get you started.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1096
Joined: Thu Feb 07, 2013 3:42 pm

Re: Why does this not work?

Postby cramsteems » Thu Sep 19, 2013 5:23 pm

OMG how stupid of me totally didn't notice!

Thanks yoriz!
cramsteems
 
Posts: 10
Joined: Thu Sep 19, 2013 5:11 pm


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest