Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import islice
- with open('pi-hex.1000000.txt', 'r') as f:
- pi = (int(i, 16) for i in f.read())
- ndigits = int('31415', 16)
- result = sum(i for i in islice(pi, ndigits) if i % 2 == 1)
- print(f'Sum of first {hex(ndigits)}={ndigits} digits of pi (in hex) = {hex(result)}={result}.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement