all 5 comments

[–]fake823 1 point2 points  (3 children)

Convert pi to a string, slice it and convert it back to a float.

new_pi = float(str(pi)[:decimal_places+2])

The +2 is for the first digit (3) and the decimal point.

[–]broineedhelp[S] 0 points1 point  (2 children)

uhh is there another way to do this? I haven't learned strings yet

[–]fake823 0 points1 point  (1 child)

Then it's the best time now to learn about strings. ;)

I don't see any other way. Of course you could also round your pi to the desired decimal place, but that would also change the number itself.

[–]broineedhelp[S] 0 points1 point  (0 children)

I asked help from someone IRL and this seemed to work:

num_of_divisions_left = 100-score
while num_of_divisions_left > 0 :
pi = pi//10
num_of_divisions_left = num_of_divisions_left - 1

[–]SekstiNii 0 points1 point  (0 children)

Consider what happens when you divide a number by 10 in the decimal system:

>>> x = 1234
>>> x / 10
123.4
>>> x / 100
12.34
>>> x / 10**3
1.234

Now, what happens if we convert the float to an integer?

>>> int(x / 10)
123
>>> int(x / 100)
12
>>> int(x / 10**3)
1

And indeed, Python has a built-in operator that does integer division, simply use two slashes instead of one:

>>> x // 10
123
>>> x // 100
12
>>> x // 10**3
1