Python Forum
Beginner Python Homework Question (Calculate Gross Pay)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner Python Homework Question (Calculate Gross Pay)
#1
I am supposed to make a code that using the function computepay() in order to calculate gross pay including time-and-a-half. In my online homework checker, it says it works fine, but whenever I try to open this .py file, it immediately terminates/closes itself. Something must be wrong, but I have no idea what. Help would be sooo appreciated!
prompt = input('Enter number of hours:\n')
hours = float(prompt)
prompt = input('Enter hourly rate:\n')
rate = float(prompt)
def computepay(hours,rate):
    if 0 <= hours <= 40:
        pay = hours * rate
    elif 40 < hours:
        pay = ((hours - 40) * rate * 1.5) + (40 * rate)
    return pay
pay = computepay(hours,rate)
print(pay)
pay = input('Press enter to exit')
Reply
#2
Quote:but whenever I try to open this .py file
What exactly do you mean by open?
It should 'run' just fine. From command line:
python progname.py
Reply
#3
The code looks OK. It should run. Probably you make some mistake when trying to run it. Check this tutorial

https://python-forum.io/Thread-How-to-Ex...ython-code
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
So it turns out, whenever I rewrote the first line in a certain order it liked it better and ran. I had to erase the first line, write prompt = ('Enter Number of Hours:\n') and then after that add input in front of that, prompt = input('Enter Number of Hours:\n'). So weird! It had been doing that everywhere
Reply
#5
(Nov-01-2018, 06:04 AM)matchamochi7 Wrote: prompt = input('Enter number of hours:\n')
(Nov-01-2018, 06:40 PM)matchamochi7 Wrote: prompt = input('Enter Number of Hours:\n')
any difference except in Number and Hours?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner Python Question: FIzz Buzz using while loop camoyn13 2 1,843 Sep-20-2022, 09:00 AM
Last Post: deanhystad
  HELP in python homework makashito 4 3,954 Oct-12-2021, 10:12 AM
Last Post: buran
  CyperSecurity Using Python HomeWork ward1995 1 1,984 Jul-08-2021, 03:55 PM
Last Post: buran
  Calculate time taken to cool down a pool in python edwinostby 0 1,821 May-24-2021, 04:12 PM
Last Post: edwinostby
Exclamation urgent , Python homework alm 2 2,335 May-09-2021, 11:19 AM
Last Post: Yoriz
  Homework with python Johnsonmfw 1 1,707 Sep-20-2020, 04:03 AM
Last Post: ndc85430
  Homework help:While Loops question Midhat_School 6 3,140 Jul-26-2020, 10:23 AM
Last Post: pyzyx3qwerty
  IF ELSE Homework Question buckthimble 1 2,173 Mar-29-2020, 06:29 AM
Last Post: buran
  Python Homework Help *Urgent GS31 2 2,613 Nov-24-2019, 01:41 PM
Last Post: ichabod801
  Python Homework Question OrcDroid123 1 2,397 Sep-01-2019, 08:44 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020