Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. # CS 1.1 - Code Quality, Reuse, & Error Handling code snippets
  2.  
  3. def foo(x):
  4. y = 0
  5. for z in x:
  6. if z == 'e':
  7. y = y +1
  8. if y == 2:
  9. return True
  10. else:
  11. return False
  12.  
  13. def two_e(str):
  14. count = 0
  15. # This loops over each char in the string
  16. for ch in str:
  17. if che == 'e':
  18. count = count +1
  19. if count == 2:
  20. return True
  21. else:
  22. return False
  23.  
  24. def printevens(x):
  25. y = 0
  26. while(y < len(x)):
  27. if y % 2 == 0:
  28. print(x[y], end = " ")
  29. y += 1
  30.  
  31. def print_evens(num_lst):
  32. """
  33. Prints the values of all even index items of a list of numbers
  34.  
  35. Uses the % operator to determine if a number is even or not.
  36.  
  37. Parameters:
  38. num_lst (list): list of numbers
  39.  
  40. Returns:
  41. list: list of only even numbers
  42.  
  43. """
  44. index = 0
  45. while index < len(num_lst):
  46. # if the index divided by 2 has no remainder, then it must be an even index
  47. if index % 2 == 0:
  48. print(num_lst[index], end = " ")
  49. index += 1
  50.  
  51. """
  52. Summary line.
  53.  
  54. Extended description of function.
  55.  
  56. Parameters:
  57. arg1 (int): Description of arg1
  58.  
  59. Returns:
  60. int: Description of return value
  61. """
  62.  
  63. madlib = (madlib.replace(wordtype, input("Enter a {}: ".format(wordtype)), 1))
  64.  
  65. for x in range(len(stories[story]["words"])):
  66. stories[story]["words"][x] = input(stories[story]["words"][x] + ": ")
  67.  
  68. exec("""\n\n# print the time\nfrom datetime import datetime\n\ndef what_time():\n\treturn 'Hey what time is it?'\n\nprint(what_time() + '\\n\\t' + str(datetime.now()))\n""")
  69.  
  70. # print the time
  71. from datetime import datetime
  72.  
  73. def what_time():
  74. return 'Hey what time is it?'
  75.  
  76. print(what_time() + '\n\t' + str(datetime.now()))
  77.  
  78. #<!doctype html>
  79.  
  80. #<html lang="en">
  81. #<head>
  82. # <meta charset="utf-8">
  83.  
  84. # <title>The HTML5 Herald</title>
  85. # <meta name="description" content="The HTML5 Herald">
  86. # <meta name="author" content="SitePoint">
  87.  
  88. # <link rel="stylesheet" href="css/styles.css?v=1.0">
  89.  
  90. #</head>
  91.  
  92. #<body>
  93. # <script src="js/scripts.js"></script>
  94. #</body>
  95. #</html>
  96.  
  97. # Returns the overtime pay a worker gets based on
  98. # the number of overtime hours worked (ot_hours)
  99. def overtime_wage(ot_hours):
  100. pay = 0
  101. if ot_hours < 5:
  102. pay = 400 + (ot_hours * 15)
  103. if ot_hours >= 5 and ot_hours < 10:
  104. pay = 400 + (ot_hours * 20)
  105. else:
  106. pay = 400 + (ot_hours * 25)
  107. return pay
  108.  
  109. def pay(ot_hours, ot_rate):
  110. return 400 + (ot_hours * ot_rate)
  111.  
  112. # Returns the overtime pay a worker gets based on
  113. # the number of overtime hours worked (ot_hours)
  114. def overtime_wage(ot_hours):
  115. ot_payment = 0
  116. if ot_hours < 5:
  117. ot_payment = pay(ot_hours, 15)
  118. if ot_hours >= 5 and ot_hours < 10:
  119. ot_payment = pay(ot_hours, 20)
  120. else:
  121. ot_payment = pay(ot_hours, 25)
  122. return ot_payment
  123.  
  124. # Try running this code
  125. try:
  126. keyboard_interaction()
  127. # if running keyboard_interaction() raises an AssertionError,
  128. # we'll catch it here
  129. except AssertionError as error:
  130. print(error)
  131. # otherwise, we execute the code in the else block
  132. else:
  133. # you can nest try/excepts into the else to catch other errors
  134. try:
  135. with open('file.log') as file:
  136. read_data = file.read()
  137. except FileNotFoundError as fnf_error:
  138. print(fnf_error)
  139. # the code here runs regardless of exceptions being raised or not
  140. finally:
  141. print('Cleaning up, irrespective of any exceptions.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement