11. What is the output of this scenario?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

What is the output of the scenario? (Using Python Programming)

11. What is the output of this scenario?
1. I have an input of an array of integers: int[] arr = { 4, 100, 2, 50, 7, -45, -23, 84, 51, 120, 98, -72 }.
2. I declare an integer variable which is named "total".
3. I created a loop.
3.1. The loop control variable value to be declared is 0. This will be represented by the variable "i"
and it represent the index of the inputted array.
3.2. The loop has a condition that if the current loop control variable value is greater than or
equal to the size of the array minus the first item of the array, the loop will break.
3.3. After the body or function is executed, the loop control variable is incremented by 2.
3.4. The body of the loop has a conditional statement. if arr[i] is even, add it to total, else minus it
%3D
to the total.
4. After the loop breaks or finishes, i want to display the value of the total.
Transcribed Image Text:11. What is the output of this scenario? 1. I have an input of an array of integers: int[] arr = { 4, 100, 2, 50, 7, -45, -23, 84, 51, 120, 98, -72 }. 2. I declare an integer variable which is named "total". 3. I created a loop. 3.1. The loop control variable value to be declared is 0. This will be represented by the variable "i" and it represent the index of the inputted array. 3.2. The loop has a condition that if the current loop control variable value is greater than or equal to the size of the array minus the first item of the array, the loop will break. 3.3. After the body or function is executed, the loop control variable is incremented by 2. 3.4. The body of the loop has a conditional statement. if arr[i] is even, add it to total, else minus it %3D to the total. 4. After the loop breaks or finishes, i want to display the value of the total.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education