Advertisement
Guest User

testcodes.py

a guest
May 20th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. #module 2 quiz
  2. print('\n*****\nMODULE 2 QUIZ')
  3. if list(range(10)) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
  4.     print("Range is correct.")
  5. else:
  6.     print("Check the range again.")
  7. if 0 % 2 == 0.0:
  8.     print('0 is correct.')
  9. else:
  10.         print('Check 0.')
  11. if 1 % 2 == 1.0:
  12.     print('1 is correct.')
  13. else:
  14.         print('Check 1.')
  15. if 2 % 2 == 0.0:
  16.     print('2 is correct.')
  17. else:
  18.         print('Check 2.')
  19. if 3 % 2 == 1.0:
  20.     print('3 is correct.')
  21. else:
  22.         print('Check 3.')
  23. if 4 % 2 == 0.0:
  24.     print('4 is correct.')
  25. else:
  26.     print:('Check 4.')
  27. print('Even number % 2, always produces 0.0\nOdd number % 2, always produces 1.0')
  28.  
  29. #module 3 quiz
  30. print('\n*****\nMODULE 3 QUIZ')
  31. def min(x, y):
  32.     if x <= y:
  33.         return x
  34.     else:
  35.         return y
  36. print(min(67, 345))
  37. print('Testing min function.')
  38. print('*****')
  39. def sum_range(x):
  40.     res = 0
  41.     for i in range(x):
  42.         res += i
  43.     return res
  44. print(sum_range(5))
  45. print('Testing sum_range function.')
  46. print('*****')
  47. def print_nums(x):
  48.     for i in range(x):
  49.         print(i)
  50.         return
  51. print(print_nums(5))
  52. print('Testing print_nums function with return statement.')
  53. print('*****')
  54. def func(x):
  55.     res = 0
  56.     for i in range(x):
  57.         res += i
  58.     return res
  59. print(func(4))
  60. print('Testing another function with loop.')
  61. print('*****')
  62.  
  63. #module 4 quiz
  64. print('\n*****\nMODULE 4 QUIZ')
  65. try:
  66.     print(1)
  67.     assert 2 + 2 == 5
  68. except AssertionError:
  69.     print(3)
  70. except:
  71.     print(4)
  72. print('Testing AssertionError.\nCheck the explanation.')
  73. print('*****')
  74.  
  75. #module 5 quiz
  76. print('\n*****\nMODULE 5 QUIZ')
  77. fib = {1:1, 2:1, 3:2, 4:3}
  78. print(fib.get(4, 0) + fib.get(7, 5))
  79. print('Value for for key 4 is 3.\nValue for key 5 is not defined, then it returns 3.')
  80. print('****')  
  81. print(['spam', 'eggs', 'ham'])
  82. print(', '.join(['spam', 'eggs', 'ham']))
  83. print('My name is Elizabeth'.replace('Elizabeth', 'Elmira'))
  84. print('spam, eggs, ham'.split(', '))
  85. print('Testing join, replace, split methods.\n*****')
  86. a = sum([11, 12])
  87. b = abs(-30)
  88. c = max(b, 2)
  89. d = min(b, c)
  90. print(d)
  91.  
  92. #e = min([sum([11, 12]), max(abs(-30), 2)])
  93. #print(e)
  94.  
  95. print([sum([11, 22]), max(abs(-30), 2)])
  96.  
  97. print(min([1, 2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement