Print pi to a number of decimal places

前端 未结 7 2455
感情败类
感情败类 2020-12-19 08:56

One of the challenges on w3resources is to print pi to \'n\' decimal places. Here is my code:

from math import pi

fraser = str(pi)

length_of_pi = []

numbe         


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-19 09:30

    As this question already has useful answers, I would just like to share how i created a program for the same purpose, which is very similar to the one in the question.

    from math import pi
    i = int(input("Enter the number of decimal places: "))
    h = 0
    b = list()
    for x in str(pi):
        h += 1
        b.append(x)
        if h == i+2:
            break
    
    h = ''.join(b)
    print(h)
    

    Thanks for Reading.

提交回复
热议问题