Python code reduction

I tried to solve this problem here: - https://www.spoj.pl/problems/PHIVAL/

Questions ask you the largest possible number of decimal digits of the golden ratio (1 + sqrt (5)) / 2, and also try to minimize the code length.

This is what I have right now. Could this code be shorter?

from decimal import *
getcontext().prec=7050
print(1+Decimal(5).sqrt())/2
+5
source share
4 answers

You can remove the space before the asterisk.

Update:

You added a part about a minor gap, so I started thinking about a different approach. If spaces are not taken into account, you can do something like this

print"1."+`map(len,"""      








       """.split("\n"))`[1::3]

. , , . , . 50 ( 2: 45) - .

+3

recursive , 19 :

print '1.%d'%len('                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ')

, , 1000000 , 10 ^ 1000000 !

+1

- ,

print 1
0

, javascript-ish- , -, Python:

import decimal
decimal.__dict__.values()[17]().prec = 7050
...

, .

0

All Articles