Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d2798f2

Browse files
Create Week5_Assignment_3_1.py
1 parent ed744bf commit d2798f2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎Week5_Assignment_3_1.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'''Write a program to prompt the user for hours and rate per hour to compute the gross pay.
2+
If hour is more than 40, the rate becomes 1.5 times the initial rate.
3+
Use try/except to catch errors.'''
4+
5+
#take input
6+
hrs = input('Enter hours: ')
7+
rate = input('Enter hourly rate: ')
8+
9+
#catch errors if any
10+
try:
11+
vhrs = float(hrs)
12+
vrate = float(rate)
13+
except:
14+
vhrs = -1
15+
vrate = -1
16+
17+
#calculate gross pay if the values are correct or else diaplay appropriate message
18+
if (vhrs>0 and vrate>0):
19+
if(vhrs>40):
20+
pay = (40*vrate)+((vhrs-40.0)*vrate*1.5)
21+
else:
22+
pay = vhrs*vrate
23+
24+
print(pay)
25+
else:
26+
print('Hour and rate must be numbers')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /