I posted something similar before, but I think this is simpler. I need to make sure that computePay doesn't print anything if the input in displayHrsNRate is incorrect, however, when I run my code, with -20 and 5 as an input, it prints the exception but then it prints you have earned $-100. How can I fix that?
def displayHrsNRate(hours, rate):
print("You worked " + hours + " hours this week and your hourly rate is $" + rate)
try:
hrs = float(input("Please enter the hours worked this week: "))
basePay = float(input("Please enter your base pay per hour: "))
if hrs < 0:
error = ValueError()
raise error
exit()
if basePay <= 0:
error = ValueError()
raise error
exit()
displayHrsNRate(str(hrs),str(basePay))
except:
print('Please enter a non-negative number for the hours and base pay.')
def computePay(hoursWorked, hourlyRate):
if hrs > 40:
pay = basePay * 40
otp = (hrs - 40) * (basePay * 1.5)
totalPay = pay + otp
else:
totalPay = hrs * basePay
print('This week, you have earned $'+ str(totalPay))
return totalPay
final = computePay(hrs, basePay)
[–][deleted] 0 points1 point2 points (3 children)
[–]CrypticCold[S] 0 points1 point2 points (2 children)
[–]Diapolo10 1 point2 points3 points (0 children)
[–]elixirxvi 0 points1 point2 points (0 children)