Due: October 30, 2020
Points: 100
Question 2 has been revised to not require recursion, as we will not have covered it.
In the examples, input is shown in red, output in black, and the character “↵” means “return” or “enter”.
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.
Here is sample output:
The string? heLlo↵ heLlo is not abcdearian The string? aLmost↵ aLmost is abcdearian The string? w3i$l0l!ow↵ w3i$l0l!ow is not abcdearian The string? e3f$f0o!rt↵ e3f$f0o!rt is abcdearian The string? cOmpuTer↵ cOmpuTer is not abcdearian The string? ABcDE↵ ABcDE is abcdearian The string? control-D
Your program must give an error message and exit if the user enters anything other than an integer.
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 -135
To turn in: Please turn in the program in the file nums.py.
Hint: You do not have to save all the numbers entered to do this. You can use the formula
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> done↵ The maximum is 13 The mean is 11.00 The minimum is 9 The variance is 2.00
Enter number> -75↵ Enter number> -135↵ Enter number> 32↵ Enter number> 127↵ Enter number> 21↵ Enter number> 138↵ Enter number> x↵ Not a number Enter number> 56↵ Enter number> done↵ The maximum is 138 The mean is 23.43 The minimum is -135 The variance is 8540.24
|
MHI 289I, Programming for Health Informatics Version of October 21, 2020 at 11:56AM
|
You can also obtain a PDF version of this. |