Skip to content
View in the app

A better way to browse. Learn more.

Tip.It Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

python

Featured Replies

i wrote a short code in python to find pi and this is what i got.

 

 

 

import math



l = 0



n = 0



z = 0



pi = 0



p = 0



t = 0



t = input("how long do you want the program to run?: ")



while l < t:



l = l + 1



n = n + 1



p = p + 1/n**2



z = p * 6



pi = math.sqrt(z)



print pi



print l



print n



print z



print "pi"



print p



print t

 

 

 

result

 

 

 

how long do you want the program to run?: 7



2.44948974278



7



7



6



pi



1



7

 

 

 

last time i looked pi != 2.44948974278 however i did it on my calcilatior and found an answer very very close to pi so i figure if i continue it will continue getting closer.

 

 

 

 

 

 

 

what i found was 2.44948974278**2 = 6

 

 

 

 

 

 

 

python is rounding the

while l < t:



  l = l + 1



  n = n + 1



  p = p + 1/n**2 

section to p = 1

 

 

 

 

 

 

 

the right answers should be simular to

pi = 3.14159



z = 9.8696



p = 1.6449

 

 

 

 

 

 

 

thank you

So is this a problem? Or do you want recognition for this amazing less-than-20-lines program? What's the point of this post, exactly? :?

  • Author

no im asking if anyone can help me fix the problem with python rounding.

 

 

 

 

 

 

 

i guess not then

python.org would have a much better equipped community to put that question to :) I don't think there would be many people on this forum that even know what python is.

no im asking if anyone can help me fix the problem with python rounding.

 

 

 

 

 

 

 

i guess not then

 

 

 

 

 

 

 

I don't know python very well, but shouldn't you set a double/single data type on those variables? I'd be guessing their integers at the moment :)

 

 

 

 

 

 

 

Sharper's right though, a python forum would be a better place.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.