Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Question 1:
- # Wikipedia's wikitext parser
- # Question 2:
- # It depends. One self-contained task (from a human perspective) would be the default, but if a set of tasks are likely to be repeated together often in a program, then it might make sense to combine them into a single function.
- #4.4
- #d) "def" is the keyword to indicate the start of a function definition, and functions must be defined before they can be called.
- #4.5
- #d)
- #4.6
- def yourpay( rate, hours ):
- try:
- rate = float(rate)
- except:
- print ( "Rate is a number, in 'merican dollars." )
- return
- try:
- hours = float(hours)
- except:
- print( "Just gimme the number of hours, nuthin' fancy." )
- return
- pay = rate * hours
- if hours > 40:
- pay += 0.5 * rate * (hours - 40)
- reply = "So, with overtime I reckon you make $" + str(pay) + ", right?"
- else:
- reply = "So, I reckon you make $" + str(pay) + ", right?"
- print( reply )
- yourpay( 10, 45 )
- #4.7
- def computegrade( score ):
- rejection = "Ur dumb. For an input, use a NUMBER, 'tween ZERO an' ONE. You fail."
- try:
- score = float(score)
- except:
- print( rejection )
- return
- if score < 0 or score > 1:
- print ( rejection )
- return
- if score < 0.6:
- grade = "F"
- elif score >= 0.9:
- grade = "A"
- elif score >= 0.8:
- grade = "B"
- elif score >= 0.7:
- grade = "C"
- elif score >= 0.6:
- grade = "D"
- else:
- grade = "F"
- print( "Ur grade is " + grade + "." )
- computegrade(0.95)
- computegrade("perfect")
- computegrade(10.0)
- computegrade(0.75)
- computegrade(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement