Question

Which of the following Python loops correctly sums up all of the integers between 1 and...

Which of the following Python loops correctly sums up all of the integers between 1 and 100 (inclusive) and stores the result in a variable called sum?

sum = 0
k = 0
while True:
sum += k
if k > 100:
  break

sum = 0
for k in 1 to 100:
sum += k

sum = 0
for k in range(100):
sum += k

sum = 0
k = 1
while k <= 100:
sum += k
k += 1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

d)

sum = 0
k = 1
while k <= 100:
sum += k
k += 1

Add a comment
Know the answer?
Add Answer to:
Which of the following Python loops correctly sums up all of the integers between 1 and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • using python 1.   Translate the following FOR loops to equivalent WHILE loops: a. for count in...

    using python 1.   Translate the following FOR loops to equivalent WHILE loops: a. for count in range(100): print(count) b. for count in range(1, 101): print(count) c. for count in range(100, 0, –1): print(count)

  • Python Code Write a program using functions and mainline logic which prompts the user to enter...

    Python Code Write a program using functions and mainline logic which prompts the user to enter a number. The number must be at least 5 and at most 20. (In other words, between 5 and 20, inclusive.) The program then generates that number of random integers and stores them in a list. The random integers should range from 0 to 100. (You can use a wider range if you want, but the lower end of the range must be at...

  • Write a program with loops that compute a.The sum of all even numbers between 2 and...

    Write a program with loops that compute a.The sum of all even numbers between 2 and 100 (inclusive). b.The sum of all squares between 1 and 100 (inclusive). c.All powers of 2 from 20 up to 220. d.The sum of all odd numbers between a and b (inclusive), where a and b are inputs. Note*: For part d, enter 3 and 21 as input Output should be: a. 2550 b. 338350 c. 1.0 2.0 4.0 8.0 ... 1048576.05 d. 120

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • ****python**** Q1. Write a recursive function that returns the sum of all numbers up to and...

    ****python**** Q1. Write a recursive function that returns the sum of all numbers up to and including the given value. This function has to be recursive; you may not use loops! For example: Test Result print('%d : %d' % (5, sum_up_to(5))) 5 : 15 Q2, Write a recursive function that counts the number of odd integers in a given list. This function has to be recursive; you may not use loops! For example: Test Result print('%s : %d' % ([2,...

  • I have to write a program in java which uses while loops. 1.prompt the user to...

    I have to write a program in java which uses while loops. 1.prompt the user to input two intergers: firstnum ans second numnumber. (first number must be smaller that the second number). 2. Output all the even numbers between first number and second number inclusive. 3. Output the sum of all the even number between first number and second number inclusive. 4 Output all the odd numbers between first number and second number inclusive. 5. Output the sum of all...

  • python la ab X, X Lab 7 Design and implement a Python program that uses a...

    python la ab X, X Lab 7 Design and implement a Python program that uses a while loop and selection statements to print the sum of the even numbers and the sum of the odd numbers (all integers) read from the keyboard. The sequence of numbers ends with a negative number: So, all numbers considered for printing the two sums are greater than or equal to 0. The sequence may be empty. Here is a possible interaction. Enter an integer:...

  • Finish the following program which adds up all integers from 0 to the user's given number inclusively using a While Loop

    // Finish the following program which adds up all integers from 0 to// the user's given number inclusively using a While Loop. The total should be// assigned to the variable 'total'.#includeusing namespace std;int main() {int number;int total = 0;int counter = 0; //initialize the variable// user enters a numbercout << "Enter a positive integer to find the summation of ";cout << "all numbers from 0 to the given number up to 100." << endl;cin >> number;// check for invalid user...

  • please can you do all just true or false 15. Python interpreter cannot detect infinite loops....

    please can you do all just true or false 15. Python interpreter cannot detect infinite loops. 16. The opposite of 1 < x and x < 10 is 1 >= *OT =< x pue x 17. 3 // 5 == 0 is True. =D%3= 18. "New York" < "New Jersey" is True. 19. range (3, 8) generates the number sequence of [3, 4, 5, 6, 7]. 20. range (5) generates the number sequence of [1, 2, 3, 4, 5].

  • Python 1. Open up IDLE and in a multiline comment write “Functions and Sets II,” your...

    Python 1. Open up IDLE and in a multiline comment write “Functions and Sets II,” your name, and the date. 2. Use Python to write a function f(n) that finds the sum of the first n positive integers. Do not use the sum() function or lists. Write the function from scratch. Then use a for loop to print the sums for n = 10, 50, 1000. 3. Finding the Image of a function Suppose that we have a function f...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT