Question

In: Computer Science

Use the function from Q1 to find the sum of ints,n, from 1 to 2500, inclusive,...

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 _____________.

Solutions

Expert Solution


# 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.


Related Solutions

Write a function sum_int( n ) to compute the sum of the integers from 1 up...
Write a function sum_int( n ) to compute the sum of the integers from 1 up to and including n.
The array s of ints contain integers each of which is between 1 and 1000 (inclusive)....
The array s of ints contain integers each of which is between 1 and 1000 (inclusive). Write code that stores in the variable ordinals the array of Strings consisting of each number followed by its ordinal number abbreviation, "st", "nd", "rd", or "th". For example if s is the array { 1, 2, 3, 4, 5, 10, 11, 12, 13, 21, 22, 973, 1000 } then your code should set ordinals to the array { "1st", "2nd", "3rd", "4th", "5th",...
Write a function called alter_sum(n)that returns the alternating sum of all the numbers from 1 to...
Write a function called alter_sum(n)that returns the alternating sum of all the numbers from 1 to n so that the first number is added, the second number is subtracted, the third number added, the fourth subtracted, and so on: 1-2+3-4+5-6+7… until you reach n. If n is 0 or less then return 0.
A triangular number is the sum of the n natural numbers from 1 to n. For...
A triangular number is the sum of the n natural numbers from 1 to n. For example: The triangular number for 3 is 1 + 2 + 3 = 6 The triangular number for 7 is 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28 Write a program segment (using a loop), that calculates and then prints the integer n and its triangular number.
Use the Integral Test to determine whether the infinite series is convergent. Sum from n=1 to...
Use the Integral Test to determine whether the infinite series is convergent. Sum from n=1 to infinity of 5/(n(n+1))
Find the vertical asymptotes (if any) of the graph of the function. (Use n as an...
Find the vertical asymptotes (if any) of the graph of the function. (Use n as an arbitrary integer if necessary. If an answer does not exist, enter DNE.) h(x) = x2 − 9 x3 + 3x2 − x − 3 (line in the middle of both functions is a division line)
Find the sum (n=5, to infinity) of the series (n2 -n)/2n
Find the sum (n=5, to infinity) of the series (n2 -n)/2n
(10 pts) Write a function called isInBetween that takes 3 ints, say n, low and high,...
(10 pts) Write a function called isInBetween that takes 3 ints, say n, low and high, and returns a boolean; the function returns true if the first parameter (n) is between the second and third parameters (low and high, INCLUSIVE), and false otherwise. Can safely assume that low is lower than high.
Determine if the following series converge or diverge. If it converges, find the sum. a. ∑n=(3^n+1)/(2n)...
Determine if the following series converge or diverge. If it converges, find the sum. a. ∑n=(3^n+1)/(2n) (upper limit of sigma∞, lower limit is n=0) b.∑n=(cosnπ)/(2) (upper limit of sigma∞ , lower limit is n= 1 c.∑n=(40n)/(2n−1)^2(2n+1)^2 (upper limit of sigma ∞ lower limit is n= 1 d.)∑n = 2/(10)^n (upper limit of sigma ∞ , lower limit of sigma n= 10)
A function calledsumOfFactorsthat takes n as a parameter and then returns the sum of the proper...
A function calledsumOfFactorsthat takes n as a parameter and then returns the sum of the proper factors/divisors ofn; for example,the sum of factorsof 20= 10+5+4+2 = 21.Note that 1 is nota properfactor of any number.Sample command => output:(display (sumOfFactors20))=> 21Hint: Calla recursivefunction sum_helperfrom sumOfFactorsfunction as follows:(define (sumOfFactors n)(sum_helper n (-n 1)))Here sum_helperfunction takes two parameters: n, d and returns the sum of all factors of n whichare <= d; for e.g. (sum_helper 20 6) returnsall proper factors of 20 which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT