Default Arguments in Python - HackerRank Solution | Easy Method
Hello Friends
आज हम आपको Hacker Rank पर Default Arguments का कंप्लीट सॉल्यूशन बताएंगे वह भी आसान भाषा में। तो दोस्तों चलिए जानते हैं सॉल्यूशन ।Problem:- Default Arguments in Python
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:
The functions works like this:
Debug the given function print_from_stream using the default value of one of its arguments.
The function has the following signature:
This function should print the first n 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 q denoting the number of queries. Each of the following line q contains a stream_name followed by integer n, and it corresponds to a single test for your function.
Constraints
- 1 <= q <= 100
- 1 <= N <= 10
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
Sample Output 0
Explanation
There are 3 queries in the sample.
In the first query, the function print_from_stream(2, OddStream()) is exectuted, which leads to printing values 1 and 3 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 2, 4 and 6 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 1, 3, 5, 7 and 9 in separated lines as the first five non-negative odd numbers.
Solution
DISCLAIMER
The above hole problem statement is given by hackerrank.com but the solution is generated by the Apna Hindi Tech authority if any of the query regarding this post or website fill the following contact form.
Related Posts
- Compress The String! Hackerrank Solution Python | Compress The String Hackerrank
- Find Angle MBC Hackerrank Solution In Python
- Word Order Hackerrank Solution In Python 3
- Default Arguments in Python - HackerRank Solution | Easy Method
- Polar Coordinates Hackerrank Solution Python | Polar Coordinates Hackerrank Solution
- Piling Up Hackerrank Solution In Python 3 | Easy Solution
Post a Comment
Post a Comment