Difference between revisions of "CSC111 Final Exam 2018"
Line 214: | Line 214: | ||
<br /> | <br /> | ||
+ | <br /> | ||
+ | =Problem 4= | ||
+ | <br /> | ||
+ | Dave, here's a bunch of banana. Can you tell me if there are two bananas next to each other that have the same weight? | ||
+ | <br /> | ||
+ | Write a program that prompts the user for a list of integers, and prints out "True" if there are two numbers in the list that are next to each other and have the same value, and it prints "False" otherwise. | ||
+ | <br /> | ||
+ | Your program must use a recursive function to determine if the there exist two consecutive numbers that have the same value. | ||
+ | <br /> | ||
+ | Examples of interactions with the program: | ||
+ | |||
+ | ==== RESTART: final4.py ==== | ||
+ | > [ ] | ||
+ | False | ||
+ | >>> | ||
+ | ==== RESTART: final4.py ==== | ||
+ | > [ 100 ] | ||
+ | False | ||
+ | >>> | ||
+ | ==== RESTART: final4.py ==== | ||
+ | > [ 100, 2 ] | ||
+ | False | ||
+ | >>> | ||
+ | ==== RESTART: final4.py ==== | ||
+ | > [ 34, 34 ] | ||
+ | True | ||
+ | >>> | ||
+ | ==== RESTART: final4.py ==== | ||
+ | > [ 1, 2, 3, 4, 1, 2, 3, 4 ] | ||
+ | False | ||
+ | >>> | ||
+ | ==== RESTART: final4.py ==== | ||
+ | > [ 1, 2, 3, 4, 5, 5 ] | ||
+ | True | ||
+ | >>> | ||
+ | ==== RESTART: final4.py ==== | ||
+ | > [ 1, 2, 3, 4, 4, 5, 6, 7 ] | ||
+ | True | ||
+ | >>> | ||
+ | |||
+ | ==Main program== | ||
+ | <br /> | ||
+ | Below is what your main program should look like. The '''lookFor2()''' function should be ''recursive''. | ||
+ | <br /> | ||
+ | ::<source lang="python"> | ||
+ | |||
+ | def main(): | ||
+ | bananas = eval(input( "> " ) ) | ||
+ | success = lookFor2( bananas ) | ||
+ | print( success ) | ||
+ | |||
+ | |||
+ | </source> | ||
+ | ==Submission== | ||
+ | <br /> | ||
+ | * Submit your program to the Final PB 4 section on Moodle. | ||
+ | |||
</onlydft> | </onlydft> |