Question

It is in python, please correct answer as soon as possibleWrite a generator function that produces a generator of the hailstone sequence. def hailstone(x): hail = hailstone(6) next(ha

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def hailstone(x):
    while x != 1:
        if x % 2 == 0:
            x //= 2
        else:
            x = 3 * x + 1
        yield x


# Testing the function here. ignore/remove the code below if not required
hail = hailstone(6)
print(next(hail))
print(next(hail))
print(next(hail))
print(next(hail))

16 Process finished with exit code o

Add a comment
Know the answer?
Add Answer to:
It is in python, please correct answer as soon as possible Write a generator function that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT