res = 0
for i in range(1, 2021):
a = list(str(i))
res += a.count('2')
print(res)
624
即约分数
total=0
def f(a,b):
x = a % b
while (x != 0):
a = b
b = x
x = a % b
return b
for i in range(1,2021):
for j in range(1,2021):
if f(i,j)==1:
total+=1
print(total)
2481215
蛇形填数
lis = [[0]*100 for row in range(100)]
num = 1
for i in range(1,101):
for j in range(i):
if i % 2 == 0:
lis[j][i-j-1] = num
else:
lis[i-j-1][j] = num
num += 1
print(lis[19][19])
761
跑步锻炼
week=6
run=0
for i in range(2000,2021):
for mouth in range(1,13):
if i == 2020 and mouth in [10,11,12] :
break
if mouth==2 and (i%400==0 or (i%4==0 and i%100!=0)):
day=29
elif mouth in [1,3,5,7,8,10,12]:
day=31
elif mouth in [4,6,9,11]:
day=30
else:
day=28
for k in range(1,day+1):
if k==1 or week==1:
run+=2
else:run+=1
week+=1
if week==8:
week=1
print(run)
8879
七段码
7+10+16+20+19+7+1=80
成绩统计
n = int(input())
a, b = 0, 0
for i in range(n):
s = int(input())
if s >= 85:
a += 1
b += 1
elif s >= 60:
b += 1
b = int(b / n * 100)
a = int(a / n * 100)
print(str(b) + "%")
print(str(a) + "%")
字串字符和
看别人的,差不多明白了
list1=list(input())
list2=[-1 for i in range(26)]
count=0
for i in range(len(list1)):
index=ord(list1[i])-ord('a')
count+=(len(list1)-i)*(i-list2[index])
list2[index]=i
print(count)