Due: October 30, 2024
Points: 100
Your program must give an error message and exit if the user enters anything other than a positive integer.
Here is sample output. Each is from a separate run of the program.
Year> 2020↵ 2020 is a leap year
Year> 2000↵ 2000 is a leap year
Year> 1900↵ 1900 is not a leap year
Year> hello↵ You must enter the year as a positive integer
Year> -12↵ You must enter the year as a positive integerTo turn in: Please turn in the program in the file leap.py.
Write a program that calls your function repeatedly, until the user enters 0 for n.
First number: 113↵ Second number (0 to stop): 293↵ The greatest common divisor of 293 and 113 is 1 First number: 14↵ Second number (0 to stop):18↵ The greatest common divisor of 18 and 14 is 2 First number: -30↵ Second number (0 to stop): -66↵ The greatest common divisor of -66 and -30 is 6 First number: 0↵ Second number (0 to stop): 7↵ The greatest common divisor of 0 and 7 is 7 First number): 7↵ Second number (0 to stop): 0↵
To turn in: Please turn in the program in the file gcd.py.
Make sure your function is recursive! Also, you only need to write the function; you do not need to write anything that calls the function.
Examples:
listdepth( [ 3, [ 4, 5 ], [ 6, [ 7, [ 8 ] ] ] ]) 4
listdepth( [ [ [ [ [ [ [ ] ] ] ] ] ] ]) 7
listdepth([ "hello [ there ]" ]) 1
listdepth(5) Should never get here – called listdepth on non-listTo turn in: Please call your function listdepth, your file listdepth.py, and submit it to Canvas
Here is sample output. Each is from a separate run of the program.
Enter number> 13↵ Enter number> 12↵ Enter number> 11↵ Enter number> 10↵ Enter number> 9↵ Enter number> xyzzy↵ Not a number Enter number> done↵ The maximum is 13 The mean is 11.00 The minimum is 9
Enter number> -75↵ Enter number> -135↵ Enter number> 32↵ Enter number> 127↵ Enter number> 21↵ Enter number> 138↵ Enter number> 56↵ Enter number> done↵ The maximum is 138 The mean is 23.43 The minimum is -135To turn in: Please turn in the program in the file nums.py.
|
ECS 235A, Computer and Information Security Version of October 30, 2024 at 3:01PM
|
You can also obtain a PDF version of this. |