Python-Project Euler 42
2014-01-18 21:15
218 查看
from math import *
file=open("e:\\words.txt")
def make(x):
sum=0
for i in range(len(x)):
sum+=(ord(x[i])-ord('A')+1)
return sum
s=file.read()
f=s.split(',')
tot=0
for i in range(len(f)):
x=f[i][1:len(f[i])-1]
num=make(x)
k=int(sqrt(2*num))
if k*(k+1)==2*num:
tot+=1
print(tot)
file.close()
file=open("e:\\words.txt")
def make(x):
sum=0
for i in range(len(x)):
sum+=(ord(x[i])-ord('A')+1)
return sum
s=file.read()
f=s.split(',')
tot=0
for i in range(len(f)):
x=f[i][1:len(f[i])-1]
num=make(x)
k=int(sqrt(2*num))
if k*(k+1)==2*num:
tot+=1
print(tot)
file.close()
相关文章推荐
- python(42):进制转换
- win7 64 安装mysql-python:_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': N
- project euler 42 Coded triangle numbers
- Learn Python The Hard Way学习(42) - 继承,包含,对象和类
- Python-Project Euler 26
- Python-Project Euler 46
- Python-Project Euler 27
- python-42: 怎么判断模拟登录是否成功
- Python 3基础教程42-锁
- Python内置函数(42)——memoryview
- Python-Project Euler 29
- 【Python第31课到42课】
- 安装MySQL-python报错:_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory或者 build\lib.win-amd64-2.7\_mysql.pyd : fatal error LNK1120: 56 unresolved externa
- Python-Project Euler 30
- Python-Project Euler 39
- Python-Project Euler 50
- Python-Project Euler 41
- Python-MySQLdb _mysql.c(42)错误
- Python-Project Euler 22