A+B
https://oj.czos.cn/problem.php?id=1000
a,b=map(int,input().split())
print(a+b)
保留两位小数的三种写法
#方法1:
print("%.2f" % 0.13333)
#方法2
print("{:.2f}".format(0.13333))
#方法3
print(round(0.13333,2))
100以内的质数
num=[];
i=2
for i in range(2,101):
for j in range(2,i):
if(i%j==0):
break
else:
num.append(i)
print(num)
a=int(input())
c=0
for i in range(2,a+1):
for j in range(2,i):
if(i%j==0):break
else:
print(i,end=' ')
c=c+1
if(c%5==0):print()
马的遍历
https://www.luogu.com.cn/problem/P1443
```python
n,m,x,y=map(int,input().split())
dx=[-1,1,2,2,1,-1,-2,-2]
dy=[2,2,1,-1,-2,-2,-1,1]
from collections import deque
res=[[-1]*m for _ in range(n)]
res[x-1][y-1]=0
qu=deque([(x-1,y-1)])
while len(qu)>0:
x,y=qu.popleft()
for i in range(8):
nx,ny=x+dx[i],y+dy[i]
if 0<= nx<n and 0<=ny<m and res[nx][ny]==-1:
res[nx][ny]=res[x][y]+1
qu.append((nx,ny))
for i in range(n):
for j in range(m):
print("{:<5}".format(res[i][j]),end="")
print()
as_index的理解
import pandas as pd
df = pd.DataFrame(data={'books':['bk1','bk1','bk1','bk2','bk2','bk3'], 'price': [12,12,12,15,15,17]})
print(df)
print()
print(df.groupby('books', as_index=True).sum())
print()
print(df.groupby('books', as_index=False).sum())
----------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------------------------------------------------------------------------


----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------
这篇博客涵盖了Python编程的基础练习,包括简单的A+B问题、数字格式化以及质数计算。还涉及了马的路径遍历问题,以及DataFrame中as_index参数的理解。文章通过实例展示了如何使用Python进行计算和数据处理,适合初学者巩固基础知识。
1141

被折叠的 条评论
为什么被折叠?



