178k views
5 votes
Write the function definition for the generato named 'generator_Magic which takes a single parameter 'n1', an Intege 1. Define the above Generator such tha it should yield the Magic constant(s) for the values starting from 3 to 'n1'. Note Printing the output will be taken care of during testing, so you need not print the Magic constants yielded by generator 'generator_Magic' and its Type. Input Format for C

User Per T
by
4.6k points

1 Answer

3 votes

Answer:

Method definition to this question can be defined as follows:

def generator_Magic(x1):#defining a method generator_Magic that accepts a variable

x = 3#defining a variable n that holds a integer value

while x <= x1:#defining while loop that check value of x less than x1

Val = (x * (( x * x) + 1)) / 2#defining val variable that calculate value

#yield val

return Val#return Val

n = n + 1#increment the value of n

Step-by-step explanation:

In the given question some of the data is missing that's why we only define the code, which can be defined as follows:

In this code a, method "generator_Magic" is declared, that hold one parameter "x1" in its parameter, and inside the method, a variable x is declared that hold an integer value and define a while loop to check value is greater than equal to "x1" and calculate the value into "Val" variable and return its value.

User Drummondj
by
5.0k points