Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #module 2 quiz
- print('\n*****\nMODULE 2 QUIZ')
- if list(range(10)) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
- print("Range is correct.")
- else:
- print("Check the range again.")
- if 0 % 2 == 0.0:
- print('0 is correct.')
- else:
- print('Check 0.')
- if 1 % 2 == 1.0:
- print('1 is correct.')
- else:
- print('Check 1.')
- if 2 % 2 == 0.0:
- print('2 is correct.')
- else:
- print('Check 2.')
- if 3 % 2 == 1.0:
- print('3 is correct.')
- else:
- print('Check 3.')
- if 4 % 2 == 0.0:
- print('4 is correct.')
- else:
- print:('Check 4.')
- print('Even number % 2, always produces 0.0\nOdd number % 2, always produces 1.0')
- #module 3 quiz
- print('\n*****\nMODULE 3 QUIZ')
- def min(x, y):
- if x <= y:
- return x
- else:
- return y
- print(min(67, 345))
- print('Testing min function.')
- print('*****')
- def sum_range(x):
- res = 0
- for i in range(x):
- res += i
- return res
- print(sum_range(5))
- print('Testing sum_range function.')
- print('*****')
- def print_nums(x):
- for i in range(x):
- print(i)
- return
- print(print_nums(5))
- print('Testing print_nums function with return statement.')
- print('*****')
- def func(x):
- res = 0
- for i in range(x):
- res += i
- return res
- print(func(4))
- print('Testing another function with loop.')
- print('*****')
- #module 4 quiz
- print('\n*****\nMODULE 4 QUIZ')
- try:
- print(1)
- assert 2 + 2 == 5
- except AssertionError:
- print(3)
- except:
- print(4)
- print('Testing AssertionError.\nCheck the explanation.')
- print('*****')
- #module 5 quiz
- print('\n*****\nMODULE 5 QUIZ')
- fib = {1:1, 2:1, 3:2, 4:3}
- print(fib.get(4, 0) + fib.get(7, 5))
- print('Value for for key 4 is 3.\nValue for key 5 is not defined, then it returns 3.')
- print('****')
- print(['spam', 'eggs', 'ham'])
- print(', '.join(['spam', 'eggs', 'ham']))
- print('My name is Elizabeth'.replace('Elizabeth', 'Elmira'))
- print('spam, eggs, ham'.split(', '))
- print('Testing join, replace, split methods.\n*****')
- a = sum([11, 12])
- b = abs(-30)
- c = max(b, 2)
- d = min(b, c)
- print(d)
- #e = min([sum([11, 12]), max(abs(-30), 2)])
- #print(e)
- print([sum([11, 22]), max(abs(-30), 2)])
- print(min([1, 2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement