In: Computer Science
Test Cases:
Enter name: Jorge
Enter wage: 9.25
Enter hours: 10
Total pay is: $92.50
Enter name: John
Enter wage: 20.00
Enter hours: 50
Total pay is: $1100 ($800 + $300 overtime)
python, keep it simple
Here I have implemented python code as per your requirement, also I have attached a screenshot of the output. Let me know in the comment section if you have any query regarding the below code.
# take input name as a string
name=input("Enter name:")
# take input wage as a float
wage=float(input("Enter wage: "))
# take input hours as a float
hours=float(input("Enter hours: "))
# if hours are greater
# than 40 then we have to
# calculate overtime salary
if hours>40:
# Calculate wage for hours>40
extra_wage=(wage*150)/100
# Calculate salary for hours<=40
regular_ans=wage*40
# Calculate salary for hours>40
overtime_ans=(extra_wage)*(hours-40)
# Calculate total pay
ans=regular_ans+overtime_ans
# here {:.8g} describe that it will remove trailing zero from the floating part.
# Here in test case 2 given output is $1100 ($800 + $300 overtime), So if i don't
# use {:.8g} then it will be print like $1100.0 ($800.0 + $300.0 overtime).
print('Total pay is: ${:.8g} (${:.8g} + ${:.8g} overtime)'.format(ans,regular_ans,overtime_ans))
else:
# Calculate salary for hours<=40
ans=wage*hours
print('Total pay is: ${:.8g}'.format(ans))
Output :