I am trying to make an iOS app that will calculate pi to a set about of decimal places based on what the user wants. I currently have a python script that will take in an integer value from the user and then use that in the calculation of Pi. I also have a swift/Xcode project that will only allow a user to input an integer value. So I am wondering if there is a way for me to pass this value that the user enters from a textbox in my swift project to then give that to the python code, run it, and then output the result? In my python code, I am using "timer" to be able to calculate the time it takes to calculate pi to the set digits that was requested. So I would only need to be able to display this result.
I have thought about rewriting the python script into swift, but I am unsure of how to do that. This is the definition I am using in my python script to calculate pi:
def pi():
decimal.getcontext().prec += 2
three = decimal.Decimal(3)
first, second, third, forth, fifth, sixth, numb = 0, three, 1, 0, 0, 24, 3
while numb != first:
first = numb
third, forth = third + forth, forth + 8
fifth, sixth = fifth + sixth, sixth + 32
second = (second * third) / fifth
numb += second
decimal.getcontext().prec -= 2
return +numb
But I was unsure of how to rewrite this into swift language, so I figured getting swift to pass the precision value into python would be easier.