In: Computer Science
Use the function from Q1 to find the sum of ints,n, from 1 to 2500,
inclusive, that satisfy the following boolean:
((n div by 11) and ( n is div by 13) ) or (n is div by 61)
Print out the sum with a labelled print:
The sum of qualifying ints, n, 1 <= n <= 2500, is ___________.
Hint: Remember that you can use a for loop to traverse a list.
For example:
L = [23,37,41,53,61]:
for n in L:
print(n, end = ' ')
23 37 41 53 61
>>>
You can do this even more easily if you use the BIF sum, which returns the sum
of the numbers in a list
L1 = [2,7,13]
Sum = sum(L1)
print(Sum)
22
Write code to find the product of every 19th qualifying int (19th, 38th,...) from Q2, then
print out a labelled print:
The product of every 19th qualifying int is ____________
Then write code to find the sum of every 2nd qualifying int (2nd,4th,...) from Q2, then
print out a labelled print:
The sum of every 2nd qualifying int is ______________
Hint: Set up a counter and initialize the counter to zero.
Increase the counter as the ints from the list returned from Q2 are traversed.
Do not use indices - just use what has been taught. You can tell from the
counter what qualified int you are currently on. Knowing this, you can determine if
you are on a 2nd or a 19th qualifying int.
What is the largest int times the sum that is less than or equal to the product?
Print this out with a labelled print statement:
The largest int times the sum that is less that or equal to the product is _____________.

# 1
nums = [n for n in range(1, 2501) if (n % 11 == 0 and n % 13 == 0)
or (n % 61 == 0)]
print('The sum of qualifying ints, n, 1 <= n <= 2500, is',
sum(nums))
# 2
# Write code to find the product of every 19th qualifying int
(19th, 38th,...) from Q2, then
nums_19thNums = [n for (i, n) in enumerate(nums) if i % 19 ==
18]
p = 1
for n in nums_19thNums:
p *= n
print('The product of every 19th qualifying int is', p)
# 3
# Then write code to find the sum of every 2nd qualifying int
(2nd,4th,...) from Q2, then
nums_19thNums_2nd = [n for (i, n) in enumerate(nums_19thNums) if i
% 2 == 1]
print('The sum of every 2nd qualifying int is',
sum(nums_19thNums_2nd))
# 4
# What is the largest int times the sum that is less than or equal
to the product?
x = p // sum(nums)
print('The largest int times the sum that is less that or equal to
the product is', x)
**************************************************
Thanks for your question. We try our best to help you with detailed
answers, But in any case, if you need any modification or have a
query/issue with respect to above answer, Please ask that in the
comment section. We will surely try to address your query ASAP and
resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.