Apr 16, 2025 | 226 words | 2 min read
4.2.2. Lucky Sum#
Write a function named lucky_sum
that accepts two integer values as
arguments. The function should calculate and return the sum of the
lucky numbers
which are all the numbers from the smallest argument to
the largest argument that are divisible by \(7\). For example, if the
numbers \(6\) and \(14\) are passed as arguments to the function, your
function should sum the numbers \(7\) and \(14\), and then return the
result. Finally, complete the template’s main
function so that the
program prompts the user to enter two integer values, calculates the lucky sum
using your lucky_sum
function, and displays the returned value.
Note
The arguments can be given in either order.
The arguments should be included in the sum if they are divisible by seven.
The function should not print anything. Keep all printing in the main function.
Sample Output#
Use the values in Table 4.2 below to test your program.
Case |
First |
Second |
---|---|---|
1 |
109 |
2165 |
2 |
57 |
42 |
3 |
-11 |
-101 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 lucky_sum_login.py Enter the first integer: 109 Enter the second integer: 2165 The sum of the lucky numbers is 334,425.
Case 2 Sample Output
$ python3 lucky_sum_login.py Enter the first integer: 57 Enter the second integer: 42 The sum of the lucky numbers is 147.
Case 3 Sample Output
$ python3 lucky_sum_login.py Enter the first integer: -11 Enter the second integer: -101 The sum of the lucky numbers is -728.
Deliverables#
Save your finished program as lucky_sum_login.py
, replacing
login
with your Purdue login. Then submit it along with all the
deliverables listed in
Table 4.3 below.
Deliverable |
Description |
---|---|
|
Your finished program. |
Screenshot(s) |
PNG(s) capturing all 3 test cases. |