Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2011
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. # Question 1:
  2. # Wikipedia's wikitext parser
  3.  
  4. # Question 2:
  5. # 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.
  6.  
  7.  
  8. #4.4
  9.  
  10. #d) "def" is the keyword to indicate the start of a function definition, and functions must be defined before they can be called.
  11.  
  12. #4.5
  13.  
  14. #d)
  15.  
  16. #4.6
  17.  
  18. def yourpay( rate, hours ):
  19.     try:
  20.         rate = float(rate)
  21.     except:
  22.         print ( "Rate is a number, in 'merican dollars." )
  23.         return
  24.     try:
  25.         hours = float(hours)
  26.     except:
  27.         print( "Just gimme the number of hours, nuthin' fancy." )
  28.         return
  29.     pay = rate * hours
  30.     if hours > 40:
  31.         pay += 0.5 * rate * (hours - 40)
  32.         reply = "So, with overtime I reckon you make $" + str(pay) + ", right?"
  33.     else:
  34.         reply = "So, I reckon you make $" + str(pay) + ", right?"
  35.     print( reply )
  36.  
  37. yourpay( 10, 45 )
  38.  
  39. #4.7
  40.  
  41. def computegrade( score ):
  42.     rejection =  "Ur dumb. For an input, use a NUMBER, 'tween ZERO an' ONE. You fail."
  43.     try:
  44.         score = float(score)
  45.     except:
  46.         print( rejection )
  47.         return
  48.     if score < 0 or score > 1:
  49.         print ( rejection )
  50.         return
  51.     if score < 0.6:
  52.         grade = "F"
  53.     elif score >= 0.9:
  54.         grade = "A"
  55.     elif score >= 0.8:
  56.         grade = "B"
  57.     elif score >= 0.7:
  58.         grade = "C"
  59.     elif score >= 0.6:
  60.         grade = "D"
  61.     else:
  62.         grade = "F"
  63.     print( "Ur grade is " + grade + "." )
  64.  
  65. computegrade(0.95)
  66. computegrade("perfect")
  67. computegrade(10.0)
  68. computegrade(0.75)
  69. computegrade(0.5)
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement