r/pythonhelp • • Apr 24 '22

So I'm making an analytical solution on python for the journey of a bouncing ball. I cannot get the code to plot the journey properly and also I get this issue " next(b, None) TypeError: 'float' object is not iterable". guidance would be appreciated!

2 Upvotes

2 comments sorted by

1

u/sentles Apr 24 '22

The issue is that itertools.chain accepts two iterables as input and it merges those into one iterable. However, the first argument you pass to it is a float, -bounce_time/2. For some reason, the function still accepts the argument, but runs into problems when you actually try to iterate through the resulting object.

Long story short, you simply have to make that argument an iterable. Replace that line with the following: return (average(t1, t2) for t1, t2 in pairwise(chain((-bounce_time / 2,), get_bounce_times(g, height, coef)))). This is essentially the same line, but I've replaced -bounce_time/2 with (-bounce_time/2,). That is now a tuple instead of a float, so the function will be able to merge it with the second argument.

Having fixed this, you also seem to have a problem with your print call at the end of your code. Seeing how I'm not even sure what you're trying to do, I'll leave it up to you.

1

u/Victory_Numerous Apr 24 '22

Your suggestion does fix the previous error i had but the code just loops infinitely now. I am trying to get a plot of heights and times throughout the journey.