Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## ex. 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).
- ## Enter Hours: 45
- ## Enter Rate: 10
- ## Pay: 475.0
- def computepay (hours, rate):
- if hours<=40:
- pay=hours*rate
- else:
- pay=(40*rate)+(hours-40)*rate*1.5
- print pay
- def userinput(a):
- a=raw_input()
- while a.isdigit()==False:
- a=raw_input("Please type a number")
- return a
- print "Please input the number of hours: "
- hours=int(userinput(hours))
- print "Please input the rate"
- rate=float(userinput(rate))
- computepay(hours,rate)
- ## ex. 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.
- ## Write a program to prompt for a score between 0.0 and 1.0.
- ## If the score is out of range print an error.
- ## If the score is between 0.0 and 1.0, print a grade using the following table:
- ## Score Grade
- ## >= 0.9 A
- ## >= 0.8 B
- ## >= 0.7 C
- ## >= 0.6 D
- ## < 0.6 F
- score = raw_input ('Please give a score \n')
- while score.isalpha () == True or float(score)>1.0:
- score = raw_input ('Please input a number between 0.0 and 1.0 for the score \n')
- def whatgrade(a):
- round(float(a))
- if a >= 0.9:
- print 'A'
- elif a >=0.8:
- print 'B'
- elif a >=0.7:
- print 'C'
- elif a >=0.6:
- print 'D'
- else: print 'F'
- whatgrade(score)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement