写在前面:
此博客仅用于记录个人学习进度,学识浅薄,若有错误观点欢迎评论区指出。欢迎各位前来交流。(部分材料来源网络,若有侵权,立即删除)
传送门:
day01基础知识
day02知识分类
day03运算符
day04数字与字符串
day05列表
day06元组与字典
day07条件与循环
day08函数概念
day09数据结构
day10模块介绍
day11文件操作
day12编程学习
day13编程学习
day14编程学习
day15编程学习
day16编程学习
day17编程学习
day18编程学习
people={}
for x in range(1,31):
people[x]=1
# print(people)
check=0
i=1
j=0
while i<=31:
if i == 31:
i=1
elif j == 15:
break
else:
if people[i] == 0:
i+=1
continue
else:
check+=1
if check == 9:
people[i]=0
check = 0
print("{}号下船了".format(i))
j+=1
else:
i+=1
continue
输出结果:
def main():
fish = 1
while True:
total, enough = fish, True
for _ in range(5):
if (total - 1) % 5 == 0:
total = (total - 1) // 5 * 4
else:
enough = False
break
if enough:
print(f'总共有{fish}条鱼')
break
fish += 1
if __name__ == '__main__':
main()
import time
print('按下回车开始计时,按下 Ctrl + C 停止计时。')
while True:
input("") # 如果是 python 2.x 版本请使用 raw_input()
starttime = time.time()
print('开始')
try:
while True:
print('计时: ', round(time.time() - starttime, 0), '秒', end="\r")
time.sleep(1)
except KeyboardInterrupt:
print('结束')
endtime = time.time()
print('总共的时间为:', round(endtime - starttime, 2),'secs')
break
# 定义立方和的函数
def sumOfSeries(n):
sum = 0
for i in range(1, n+1):
sum +=i*i*i
return sum
# 调用函数
n = 5
print(sumOfSeries(n))
# 定义函数,arr 为数组,n 为数组长度,可作为备用参数,这里没有用到
def _sum(arr,n):
# 使用内置的 sum 函数计算
return(sum(arr))
# 调用函数
arr=[]
# 数组元素
arr = [12, 3, 4, 15]
# 计算数组元素的长度
n = len(arr)
ans = _sum(arr,n)
# 输出结果
print ('数组元素之和为',ans)
for循环实现
list=[1,3,5,7,9,34]
sum=0
for i in range(0,len(list)):
sum+=list[i]
print(sum)
def leftRotate(arr, d, n):
for i in range(d):
leftRotatebyOne(arr, n)
def leftRotatebyOne(arr, n):
temp = arr[0]
for i in range(n-1):
arr[i] = arr[i+1]
arr[n-1] = temp
def printArray(arr,size):
for i in range(size):
print ("%d"% arr[i],end=" ")
arr = [1, 2, 3, 4, 5, 6, 7]
leftRotate(arr, 2, 7)
printArray(arr, 7)
def leftRotate(arr, d, n):
for i in range(gcd(d,n)):
temp = arr[i]
j = i
while 1:
k = j + d
if k >= n:
k = k - n
if k == i:
break
arr[j] = arr[k]
j = k
arr[j] = temp
def printArray(arr, size):
for i in range(size):
print ("%d" % arr[i], end=" ")
def gcd(a, b):
if b == 0:
return a;
else:
return gcd(b, a%b)
arr = [1, 2, 3, 4, 5, 6, 7]
leftRotate(arr, 2, 7)
printArray(arr, 7)
def swapList(newList):
size = len(newList)
temp = newList[0]
newList[0] = newList[size - 1]
newList[size - 1] = temp
return newList
newList = [1, 2, 3]
print(swapList(newList))
def swapList(newList):
newList[0], newList[-1] = newList[-1], newList[0]
return newList
newList = [1, 2, 3]
print(swapList(newList))
def swapList(list):
get = list[-1], list[0]
list[0], list[-1] = get
return list
newList = [1, 2, 3]
print(swapList(newList))