Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Exercise 4.4
- # What is the purpose of the ”def” keyword in Python?
- # b
- # Exercise 4.5
- # What will the following Python program print out?
- # d
- # Exercise 4.6
- # Rewrite your pay computation with
- # time-and-a-half for overtime and create a
- # function called computepay which takes two
- # parameters (hours and rate).
- def computepay( hours, rate ):
- if hours <= 40:
- pay = hours * rate
- else:
- hours2 = hours - 40
- pay = 40 * rate + 15 * hours2
- print 'Pay:', pay
- hs = int(raw_input('Enter Hours:'))
- re = int(raw_input('Enter Rate:'))
- computepay(hs, re)
- # Exercise 4.7
- # Rewrite the grade program from the previous
- # chapter using a function called computegrade
- # that takes a score as its parameter and
- # returns a grade as a string.
- def computegrade(score):
- if score > 0.9:
- return 'A'
- elif score > 0.8:
- return 'B'
- elif score > 0.7:
- return 'C'
- elif score > 0.6:
- return 'D'
- elif score <= 0.6:
- return 'F'
- else:
- return 'bad score'
- input = raw_input('Enter score: ')
- try:
- sc = float(input)
- if sc < 10.0:
- print computegrade(sc)
- else:
- print 'Bad score'
- except:
- print 'Bad score'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement