In this challenge, the task is to debug the existing code to successfully execute all provided test files. Python supports a useful concept of default argument values. For each keyword argument of a function, we can assign a default value which is going to be used as the value of said argument if the function is called without it. For example, consider the following increment function: defincrement_by(n,increment=1):returnn+increment The functions works like this: >>>increment_by(5,2)7>>>increment_by(4)5>>> Debug the given function print_from_stream using the default value of one of its arguments. The function has the following signature: defprint_from_stream(n,stream) This function should print the first  values returned by get_next() method of stream object provided as an argument. Each of these values should be printed in a separate line. Whenever the function is called without the stream argument, it should use an instance of EvenStream class defined in the code stubs below as the value of stream. Your function will be tested on several cases by the locked template code. Input Format The input is read by the provided locked code template. In the first line, there is a single integer  denoting the number of queries. Each of the following  lines contains a stream_name followed by integer , and it corresponds to a single test for your function. Constraints     Output Format The output is produced by the provided and locked code template. For each of the queries (stream_name, n), if the stream_name is even then print_from_stream(n) is called. Otherwise, if the stream_name is odd, then print_from_stream(n, OddStream()) is called. Sample Input 0 3odd 2even 3odd 5 Sample Output 0 1302413579 Explanation 0 There are  queries in the sample. In the first query, the function print_from_stream(2, OddStream()) is exectuted, which leads to printing values  and  in separated lines as the first two non-negative odd numbers. In the second query, the function print_from_stream(3) is exectuted, which leads to printing values  and  in separated lines as the first three non-negative even numbers. In the third query, the function print_from_stream(5, OddStream()) is exectuted, which leads to printing values  and  in separated lines as the first five non-negative odd numbers.

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

In this challenge, the task is to debug the existing code to successfully execute all provided test files.

Python supports a useful concept of default argument values. For each keyword argument of a function, we can assign a default value which is going to be used as the value of said argument if the function is called without it. For example, consider the following increment function:

defincrement_by(n,increment=1):returnn+increment

The functions works like this:

>>>increment_by(5,2)7>>>increment_by(4)5>>>

Debug the given function print_from_stream using the default value of one of its arguments.

The function has the following signature:

defprint_from_stream(n,stream)

This function should print the first  values returned by get_next() method of stream object provided as an argument. Each of these values should be printed in a separate line.

Whenever the function is called without the stream argument, it should use an instance of EvenStream class defined in the code stubs below as the value of stream.

Your function will be tested on several cases by the locked template code.

Input Format

The input is read by the provided locked code template. In the first line, there is a single integer  denoting the number of queries. Each of the following  lines contains a stream_name followed by integer , and it corresponds to a single test for your function.

Constraints

  •  
  •  

Output Format

The output is produced by the provided and locked code template. For each of the queries (stream_name, n), if the stream_name is even then print_from_stream(n) is called. Otherwise, if the stream_name is odd, then print_from_stream(n, OddStream()) is called.

Sample Input 0

3odd 2even 3odd 5

Sample Output 0

1302413579

Explanation 0

There are  queries in the sample.

In the first query, the function print_from_stream(2, OddStream()) is exectuted, which leads to printing values  and  in separated lines as the first two non-negative odd numbers.

In the second query, the function print_from_stream(3) is exectuted, which leads to printing values  and  in separated lines as the first three non-negative even numbers.

In the third query, the function print_from_stream(5, OddStream()) is exectuted, which leads to printing values  and  in separated lines as the first five non-negative odd numbers.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
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