Starting from:

$30

CSC401 – Introduction to Programming 6 Solved

In this assignment, you will create 3 recursive functions as described below.  You can put the 3 functions in the same file. 

1)      Create a recursive function based upon the “countdown” function from the text (Chapter 10, pg 332) called “timer” that waits 1 second for each count and prints a message when the countdown expires.  Assume all inputs will be integer values. Sample output:

timer(5) 5 <1 sec pause> 

4 <1 sec pause> 

3 <1 sec pause> 

2 <1 sec pause> 

1 <1 sec pause> 

Timer Done 

2)      Create a function “find_file” that accepts a full directory path parameter (i.e., C:\Users\cs401\Desktop\Docs) and a file name parameter  (i.e., MyFile.txt) that recursively searches all folders and subfolders under the provided path for the specified filename. When found, the full file pathname should be printed. Note there may be multiple files that match the specified name. If the file is not found, nothing should be printed. If listing the files in a folder results in a PermissionError – skip that folder but continue processing. Sample output:

find_file("C:\\Users\\cs401\\Desktop\\Docs", "build.xml")  

C:\Users\Hieldc\Desktop\Docs\Arrays\Arrays\build.xml 

C:\Users\Hieldc\Desktop\Docs\comm\Client\build.xml 

C:\Users\Hieldc\Desktop\Docs\JavaApplication41\build.xml 

3)      Assume a game (like monopoly) has fake money that needs to be distributed as efficiently as possible throughout the game. Create a function that accepts a dollar amount (i.e., $126) and returns a string indicating the most efficient set of paper bills that make up that amount (i.e., “$50 $50 $20 $5 $1”). Assume the set of paper bills available in the game are: $1, $5, $10, $20 & $50.

Sample inputs & outputs:

                                  $12 è “$10 $1 $1”                                                                                     $63 è “$50 $10 $1”

                                 $100 è “$50 $50”                                                                                       $88 è “$50 $20 $10 $5 $1 $1 $1”

                                 $181 è “$50 $50 $50 $20 $10 $1”                                                       $69 è “$50 $10 $5 $1 $1 $1 $1”

 

4)      Create a separate “main” python module that calls/tests each of the above 3 functions

More products