Commit aa3f81d0 by BellCodeEditor

auto save

parent 49bd11e5
Showing with 44 additions and 29 deletions
#输入“年月日”,输出是一年中的第几天
## 输入年月日,判断是一年的多少天
def getN(year,month,day):
sum = 0 ## 到最后在判断是闰年还是平年
for i in range(0,month):
sum += m[i]
sum += day
if (year%400==0) or (year%4==0 and year%10!=0 ): ## 表示是闰年
sum += 1
return sum
year = input("year : ") ## 输出数据
month = input("month : ")
day = input("day : ")
m = [0,31,28,31,30,31,30,31,31,30,31,30] ## 只包括前 11 个月
year = int(year)
month = int(month)
day = int(day)
print( getN(year,month,day))
#输入n个正整数将其存储到一个列表中,然后从小到大升序排列
#第一步:存储
num_list = []
n = int(input("请输入要输入数字的个数:"))
n = int(input("请输入需要的数字个数:"))
for i in range(n):
num = int(input("输入第"+str(i+1)+"个数字:"))
num = int(input("输入的第"+str(i+1)+"个数"))
num_list.append(num)
for i in range(n):
#冒泡排序:从小到大
for i in range(n-1):
for j in range(n-1-i):
if num_list[j] > num_list[j+1]:
num_list[j],num_list[j+1] = num_list[j+1],num_list[j]
print(num_list)
print(num_list)
\ No newline at end of file
[5,8,6,3,9,2,1,7]
#第一轮
[5,6,3,8,2,1,7,9]
#第二轮
[5,3,6,2,1,7,8,9]
#第三轮
[3,5,2,1,6,7,8,9]
#第四轮
[3,2,1,5,6,7,8,9]
#第五轮
[2,1,3,5,6,7,8,9]
#第六轮
[1,2,3,5,6,7,8,9]
#冒泡排序的实现原理
def b_l(l):
n = len(l)
#i表示第几轮
for i in range(0,n-1):
#j表示列表的下标
for j in range(0,n-1-i):
#比大小
if l[j] > l[j+1]:
l[j],l[j+1] = l[j+1],l[j]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment