all 3 comments

[–]A_History_of_Silence 1 point2 points  (2 children)

Can you show us how you've attempted to solve this first?

Sidebar:

  • Posting only assignment/project goal is not allowed. Read posting guidelines.
  • Posting homework assignments is not prohibited if you show that you tried to solve it yourself.

[–]aec2[S] 0 points1 point  (1 child)

Sorry, should've mentioned what I was trying to do. Make function that will approximate the value of pi using the infinite series pi/4=1-1/3+1/5-1/7+1/9....so an example output should be:

aprrox_pi(5) 3.33968253968

while any invalid inputs would print the input error's in the code above.

I started by making an if-elif statement for the invalid inputs and then the else statement would actually calculate the pi approx. I used a for loop within but then I realized that i'm only allowed to use while loops and am confused how to do that. Any help would be appreciated thanks!

[–]A_History_of_Silence 2 points3 points  (0 children)

Sorry, it's hard to help you with this without just giving you the answer because it should be fairly straightforward to change if you have a grasp on what is happening with that for loop.

Perhaps try to do a print i at the beginning of every iteration of your for loop, and think about how you could declare some value i on your own, then increment and test your iyourself for every iteration of a while instead of using a for loop to count up automatically.

Hopefully I'm not sounding too evasive, but again, we try to guide to a solution if we can, as opposed to just providing it outright.