1 Star 0 Fork 0

toliong/pythont

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test.py 3.98 KB
一键复制 编辑 原始数据 按行查看 历史
Bman 提交于 2018-01-31 17:11 . Some practise
#!/usr/bin/env python3
# --*-- coding:UTF-8 --*--
# date : 2018-01-11
def not_rep(alist):
result_list = []
sorted(alist)
for item in alist:
if item not in result_list:
result_list.append(item)
return result_list
# <<python编程快速上手-让繁琐工作自动化>> 3.11.1 collatz序列
def collatz(number):
if number % 2 == 0:
print("number是偶数, number // 2 的值为 %d" % (number//2) )
return number//2
elif number % 2 == 1:
print("number是奇数, 3*number +1 的值为 %d" % (3*number+1) )
return 3*number+1
def run(number):
while True:
result = collatz(int(number))
if result != 1:
number = result
else:
print("Result is 1.")
break
#run(3)
# <<python编程快速上手-让繁琐工作自动化>> 4.10.1 逗号代码
def list2str(alist):
if isinstance(alist,list):
for item in range(len(alist)-1):
print(" %s" % (alist[item]) , end=",")
print(" and %s" % alist[-1])
else:
print("Please make sure parameter is a list.")
#list2str(["a",3,'c',['a','b','c']])
# <<python编程快速上手-让繁琐工作自动化>> 4.20.2 字符图网格
# import sys
#
# def time_difference(start,stop): # start格式 xx:xx:xx stop格式:xx:xx:xx
# " 时间差转换成秒 "
# if isinstance(start,str) and isinstance(stop,str):
# start_list = []
# stop_list = []
# try:
# for item in range(3):
# start_list.append(int(start.split(':')[item]))
# stop_list.append(int(stop.split(':')[item]))
# except ValueError:
# print("请用阿拉伯数字表示时间")
# sys.exit(4)
#
# # "时间范围是否正确"
# for item in range(3):
# if item == 0 and start_list[0] > 24 or start_list[0] < 0 or stop_list[0] > 24 or stop_list[0] < 0 :
# print("请输入正确的小时时间范围")
# sys.exit(1)
# if item == 1 and start_list[1] > 60 or start_list[1] < 0 or stop_list[1] > 60 or stop_list[1] < 0:
# print("请输入正确的分钟时间范围")
# sys.exit(2)
# if item == 0 and start_list[0] > 24 or start_list[0] < 0 or stop_list[0] > 24 or stop_list[0] < 0 :
# print("请输入正确的分钟时间范围")
# sys.exit(3)
#
# # 计算时间差
# if stop_list[0] > start[0]:
# timeis = (stop_list[0] * 60**2 + stop_list[1] * 60)
#
# print(start_list,stop_list)
# import time
#
# def time_difference(start,stop):
# tmp_date = "2010-01-10 "
# # 开始时间的时间戳
# start_date = tmp_date + start
# start_st = time.strptime(start_date, '%Y-%m-%d %H:%M:%S')
# start_time_stamp = time.mktime(start_st)
#
# # 结束时间的时间戳
# stop_date = tmp_date + stop
# stop_st = time.strptime(stop_date, '%Y-%m-%d %H:%M:%S')
# stop_time_stamp = time.mktime(stop_st)
#
# if start_time_stamp <= stop_time_stamp:
# timeis = int(stop_time_stamp - start_time_stamp)
# print(stop_time_stamp,start_time_stamp)
# print("时间差是 %d" % timeis)
# else:
# timeis = int(stop_time_stamp + 86400 - start_time_stamp)
# print(stop_time_stamp,start_time_stamp)
# print("时间差是 %d" % timeis)
#
# time_difference("17:55:31","4:21:57")
def list_year_value(alist):
"字符图形格式输出每月的值"
blist = alist[:]
alist.sort()
max_value = alist[-1]
for each_value in range(max_value,0,-1):
print("|",end="")
for each_month in range(12):
if blist[each_month] >= each_value:
print("*",end=" ")
else:
print(" ",end=" ")
print("")
print("-" * 30)
print("1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月 ")
list_year_value([7, 3, 2, 9, 5, 1, 4, 0, 2, 8, 3, 9])
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/toliong/pythont.git
git@gitee.com:toliong/pythont.git
toliong
pythont
pythont
master

搜索帮助