• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
 






Apollo

 
 

Powered by 博客园
| | 新随笔 | | | 管理

2018年12月30日

Python字符串反转操作
摘要: #!/usr/bin/python # -*- coding: UTF-8 -*- # 字符串反转操作 lst = [] def output(str, length): if length == 0: return lst lst.append(str[length - 1]) output(str, length - 1) str = inp... 阅读全文
posted @ 2018-12-30 23:02 阿波罗Apollo 阅读(188) 评论(0) 推荐(0)
 
Python利用递归计算年龄
摘要: 已知有五位朋友在一起。第五位朋友他说自己比第4个人大2岁;问第4个人岁数,他说比第3个人大2岁;问第三个人,又说比第2人大两岁;问第2个人,说比第一个人大两岁;最后问第一个人,他说是10岁。要求:求第5个人的年龄是多少。 阅读全文
posted @ 2018-12-30 22:44 阿波罗Apollo 阅读(910) 评论(0) 推荐(0)
 
Python判断字符串1234321是不是回文
摘要: #!/usr/bin/env python # -*- coding:utf-8 -*- num = int(input("请输入一个数字:\n")) x = str(num) flag = True # 判断1234321是不是回文数 for i in range(len(x) // 2): if x[i] != x[-i - 1]: flag = False ... 阅读全文
posted @ 2018-12-30 13:18 阿波罗Apollo 阅读(478) 评论(0) 推荐(0)
 
Python if控制流语句
摘要: #!/usr/bin/env python # -*- coding:utf-8 -*- # Python if控制流语句 letter = input("please input:") if letter == 'S': print('please input second letter:') letter = input("please input:") if l... 阅读全文
posted @ 2018-12-30 13:01 阿波罗Apollo 阅读(135) 评论(0) 推荐(0)
 
Python列表反转操作
摘要: # 列表反转1 a = [99, 66, 25, 10, 3] a.reverse() print(a) # 列表反转2 a = [99, 66, 25, 10, 3] print(a[::-1]) # 列表反转3 a = [145, 130, 120, 99, 66, 25, 10, 3] N = len(a) for i in range(len(a) // 2): a[i]... 阅读全文
posted @ 2018-12-30 12:54 阿波罗Apollo 阅读(295) 评论(0) 推荐(0)
 
Python join()逗号分割列表
摘要: #!/usr/bin/env python # -*- coding:utf-8 -*- lst = [1,2,3,4,5] str = '-'.join(str(n) for n in lst) print(str) 阅读全文
posted @ 2018-12-30 12:50 阿波罗Apollo 阅读(658) 评论(0) 推荐(0)
 
Python基础函数调用
摘要: #!/usr/bin/env python # -*- coding:utf-8 -*- def func1(): print('hello world !') def func2(): for i in range(3): func1() if __name__ == '__main__': func2() 阅读全文
posted @ 2018-12-30 12:45 阿波罗Apollo 阅读(242) 评论(0) 推荐(0)
 
Python设置文本文字颜色
摘要: 提示:此时文字颜色为pink提示:此时文字颜色为blue提示:此时文字颜色为green提示:此时文字颜色为yellow提示:此时文字颜色为red提示:此时文字颜色为black提示:此时文字颜色为black+underline提示:此时文字颜色为black+bold 阅读全文
posted @ 2018-12-30 12:40 阿波罗Apollo 阅读(2434) 评论(0) 推荐(1)
 
Python函数名挂载变量
摘要: def func(x,y): mysum = x+y return mysum func.name = 'apollo' print(func.name) # apollo # print(func.age) # 不挂载,获取会报错 # AttributeError: 'function' object has no attribute 'age' 阅读全文
posted @ 2018-12-30 12:26 阿波罗Apollo 阅读(107) 评论(0) 推荐(0)
 
python输出指定区间范围内的素数
摘要: #!/usr/bin/env python # -*- coding:utf-8 -*- # 输出指定范围内的素数 lower = int(input("请您输入区间最小值: ")) upper = int(input("请您输入区间最大值: ")) lst = [] for num in range(lower,upper + 1): # 素数大于 1 if num > 1:... 阅读全文
posted @ 2018-12-30 12:21 阿波罗Apollo 阅读(3427) 评论(0) 推荐(0)
 
python对数组插入排序
摘要: #!/usr/bin/env python # -*- coding:utf-8 -*- lst = [5,1,4,3,2] for i in range(len(lst) - 1): for j in range(i + 1, len(lst)): if lst[i] > lst[j]: lst[i], lst[j] = lst[j], lst... 阅读全文
posted @ 2018-12-30 12:10 阿波罗Apollo 阅读(303) 评论(0) 推荐(0)
 
Python求3*3矩阵对角线元素之和
摘要: #!/usr/bin/env python # -*- coding:utf-8 -*- """ # 3*3矩阵对角线元素之和 1 2 3 4 5 6 7 8 9 # array = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]] """###########################... 阅读全文
posted @ 2018-12-30 11:33 阿波罗Apollo 阅读(7237) 评论(0) 推荐(0)
 
Python数组插入排序
摘要: # Python数组插入排序 a = [1, 4, 6, 9, 13] number = int(input("insert a new number:\n")) end = a[len(a) - 1] if number > end: a.append(number) else: for i in range(len(a)): if a[i] > number:... 阅读全文
posted @ 2018-12-30 11:11 阿波罗Apollo 阅读(346) 评论(0) 推荐(0)