Calculation of hours worked

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imran akhtar
    New Member
    • Nov 2008
    • 64

    Calculation of hours worked

    #Workers in a company are paid £8 per hour for each hour they work up to a
    #basic working week of 40 hours, and £12 an hour for any overtime they work.
    #Write a program that asks the user to enter the number of hours worked
    #and outputs the total pay for the week.

    below is the which i have made, can cheak to see if it works. thnaks you

    Code:
    workedhours = input ("\nPlease enter number of hours worked this week: ")
    while workedhours > 40:
        workedhours = input("Incorrect, please enter worked hours this week again:")
    
    overtime = input ("Please enter number of overtime horus worked this week: ")
    
    if workedhours <= 40:
        print "\n\nStandard hourly rate is £8 per hour, so you will get paid: \t£",8*workedhours
        
    elif workedhours >= 40:
        print "Standard hourly rate is £8 per hour, so you will get paid: \t£",8*workedhours
        
    print "Overtime rate is £12 per hour, so you will get paid: \t\t£",12*overtime
    
    print "\nTotal pay for the week is: \t\t\t\t\t£",8*workedhours + 12*overtime
    Last edited by bvdet; Dec 16 '08, 04:03 PM. Reason: Moved to new thread, added code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Please use code tags!! It works like this:
    [code] .......code goes here......... [/code]
    I created a new thread for you because you have asked a question unrelated to your previous question.

    -BV

    Comment

    • imran akhtar
      New Member
      • Nov 2008
      • 64

      #3
      ok sorry, next time will do that, so can you cheak program, and see if works correclty.

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        Yes, it works. Why did you need me to test it for you? You should test your own code by using an IDE such as IDLE. You can also run your script from the command prompt.

        A couple of suggestions:

        Use raw_input() instead of input(). This will avoid the possibility of someone entering malicious code.

        Set up a while loop to validate the initial entry that should be 40 hours or less. Something like this:
        Code:
        while True:
            workedhours = int(raw_input("\nPlease enter number of hours worked this week: "))
            if workedhours > 40:
                print "Incorrect, please enter worked hours this week again (must not be over 40)."
            else: break
        You don't need the if statement "if workedhours <= 40".

        -BV

        Comment

        • imran akhtar
          New Member
          • Nov 2008
          • 64

          #5
          fucntions

          i have to Write a function called areaOfCircle() which takes as an input the radius and outputs the area of a circle with a radius of the given input (area = r2)

          basically i am confused wht it means by write a fucntion, i have the code for this, but wht does it mean wirte a function. i have attched wht i have wriiten.
          Attached Files

          Comment

          • bvdet
            Recognized Expert Specialist
            • Oct 2006
            • 2851

            #6
            Please, imran akhtar, do not ask new and unrelated questions in the same thread. Start a new thread. Please post your code in your message and enclose the code with code tags. This is preferable to viewing an attachment.

            -BV

            Comment

            • imran akhtar
              New Member
              • Nov 2008
              • 64

              #7
              ok sorry for that, silly question how do i start . Start a new thread., due to the fact i cant seem find tab which says "NEW THREAD" and how does the enclose code tags looks like. sorry for the stupid questions.

              Comment

              • bvdet
                Recognized Expert Specialist
                • Oct 2006
                • 2851

                #8
                Under bytes > topic > python > answers, there should be a large button in the upper left of the window: "New Thread"

                Code tags work like this:
                [code]x + y = z
                print z
                [/code]

                There is a code tag button on the toolbar in the "Reply to Thread" and "Post New Thread" windows. Highlight all your code, then select the code tag button.

                Comment

                • imran akhtar
                  New Member
                  • Nov 2008
                  • 64

                  #9
                  no mate there is no button called NEW THREAD, thats the reason i been just posting new question and in the old thread, due to fact i could not find the button.

                  Comment

                  • bigturtle
                    New Member
                    • Apr 2007
                    • 19

                    #10
                    Do what bvdet says -- don't just look at your own thread! Instead, go all the way up to the top of the window above your thread, where it says "bytes > topic > python > answers", and click on "answers". Then you will see the "New Thread" button.

                    If you learn how the forum works, you will be so much more productive and people will be more willing to help you.

                    Comment

                    • bvdet
                      Recognized Expert Specialist
                      • Oct 2006
                      • 2851

                      #11
                      Thanks bigturtle. I could not have said it better!

                      -BV

                      Comment

                      Working...