题目:
1:L = [ ['Apple', 'Google', 'Microsoft'], ['Java', 'Python', 'Ruby', 'PHP'], ['Adam', 'Bart', 'Lisa']] 打印Apple、Python、Lisa
2:完成列表a=[1,7,4,89,34,2]的冒泡排序(冒泡排序:小的排前面,大的排后面。),并写出冒泡的原理是什么?(很重要)
3:利用input函数从控制台获取一个当前日期,如:20181031,然后利用自己所学知识,把他转换成 "2018年10月31号"
答案:
# -*- coding:utf-8 -*-
'''
@project: jiaxy
@author: Jimmy
@file: work_2018_11_01.py
@ide: PyCharm Community Edition
@time: 2018-11-01 09:43
@blog: https://www.cnblogs.com/gotesting/
'''
# Work1
L = [['Apple','Google','Microsoft'],['Java','Python','Ruby','PHP'],['Adam','Bart','Lisa']]
print(L[0][0],L[1][1],L[2][2])
# Work2
'''
冒泡排序原理:
两个两个以向后位移的方式比较大小
'''
a=[1,7,4,89,34,2]
def bubble_sort(a):
len_a = len(a)
for i in range (0,len_a-1):
for j in range(0,len_a-1-i):
if a[j] > a [j+1]:
a[j],a[j+1] = a[j+1],a[j]
bubble_sort(a)
print(a)
# Work3
t =input('请输入当前日期,格式为:YYYYMMDD,如20181101 ')
year = t[0:4]
month = t[4:6]
day = t[6:8]
new_t = year + '年' + month + '月' + day + '日'
print(new_t)