Question
Asked Oct 13, 2019
399 views

Python 3.7.4:

Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates, it prints out, on a line by itself, the sum of all the even integers read.

check_circle

Expert Answer

Step 1

Following is the program code that takes input from the user all positive integer and terminates if the integer is not positive. Finally, it prints out, the sum of all the even integers read.

In the following python program code:

while() is used to make sure the number entered by user is always positive. Inside the while() loop  if (n < 0) condition checks for non-positive integer inputted by user and exit the while() loop using break. if(n%2==0) condition is used to add all even integers in variable sum.

Step 2

Sum = 0 #variable to store sum of all even integers

n=1 #variable to take input from user

while(n>0): #loop to make sure input, integer is positive

   n = int(input("Enter positive integer ")) #storing input integer in variable n

   if (n < 0): #It will ex...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ...

A: Create a JAVA class of name AtmSimulator. Import DecimalFormat class to display balance up to 2 deci...

question_answer

Q: Provide a situation that encompasses Confidentiality in the CIA triad

A: Answer:Situation of Confidentiality:Confidentiality comes under the C.I.A (Confidentiality Integrity...

question_answer

Q: Make truth tables, then use them to create equations in SOP and POS format. Explain your steps.1) xy...

A: Truth table for the expression: F = xyz+ x~(yz) + ~(xyz)

question_answer

Q: Write a program in Python for a (very) rudimentary shooter "game". You are the only shooter and you ...

A: NOTE: Sample output is missing in the question. The following program is executed for own sample out...

question_answer

Q: Suppose you have two tables: EMPLOYEE and EMPLOYEE_1. The EMPLOYEE table contains the records for th...

A: Two tables are given named as EMPLOYEE and EMPLOYEE1. Each table has its records. EMPLOYEE table has...

question_answer

Q: Describe the GRANT statement and explain how it relates to security. What types of privileges may be...

A: The syntax for GRANT statement is GRANT parameter(1) ON parameter(2) TO parameter(3) [WITH GRANT OPT...

question_answer

Q: Explain why storing secret encryption/ decryption keys in a removable drive helps defend against col...

A: DefinitionA cold boot attack is basically a procedure to get unauthorized access to the encryption k...

question_answer

Q: Consider a program that declares global integer variables x, y[10]. Thesevariables are allocated sta...

A: Explanation of the code: lw $s1, 0($gp) #load value in base address to $s1addi $s1, $s1, 25 #increme...

question_answer

Q: Suppose the author of an online banking software system has programmed in a secret feature so that p...

A: Since the program was hidden and only activated when the account balance just got over $10,000, the ...