标签:name time localtime break load end git for http
#!/usr/bin/python
# -*- coding:utf-8 -*-
import time
# 格式化成2016-03-20 11:45:39形式
nowTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(nowTime)
def ThreeNum():
three = []
count = 0
for i in range(100, 1000):
n1 = i // 100 # 取整除 百位
n2 = (i - n1 * 100) // 10 # 十位
n3 = i % 10 # 个位
n = pow(n1, 3) + pow(n2, 3) + pow(n3, 3)
if i == n:
count = count + 1
three.append(n)
print("水仙花数有 %s 个:%s" % (count, three))
def FourNum():
four = []
count = 0
for i in range(1000, 10000):
n1 = i // 1000 # // 取整除 千位
n2 = (i - n1 * 1000) // 100 # 百位
n3 = i % 10 # 个位
n4 = (i - n1 * 1000 - n2 * 100) // 10 # 十位
n = pow(n1, 4) + pow(n2, 4) + pow(n3, 4) + pow(n4, 4)
if i == n:
count = count + 1
four.append(n)
print("四叶玫瑰数有 %s 个:%s" % (count, four))
def FiveNum():
five = []
count = 0
for i in range(10000, 100000):
n1 = i // 10000 # 取整除 万位
n2 = (i - n1 * 10000) // 1000 # 千位
n3 = i % 10 # 个位
n4 = (i - n1 * 10000 - n2 * 1000) // 100 # 百位
n5 = (i - n1 * 10000 - n2 * 1000 - n4 * 100) // 10 # 十位
n = pow(n1, 5) + pow(n2, 5) + pow(n3, 5) + pow(n4, 5) + pow(n5, 5)
if i == n:
count = count + 1
five.append(n)
print("五角星数有 %s 个:%s" % (count, five))
if __name__ == "__main__":
while True:
print(‘‘‘
-------------开始------------------
请选择菜单:
(0) 退出
(1) 水仙花数
(2) 四叶玫瑰数
(3) 五角星数
----------------------------------
‘‘‘)
number_str = input("请输入执行序号:")
# if number_str == "":
# continue
if number_str.isdigit():
number = int(number_str)
else:
print("输出错误,请重新输入!")
continue
if number == 0:
print("正在退出程序。。。")
break
elif number == 1:
ThreeNum()
elif number == 2:
FourNum()
elif number == 3:
FiveNum()
else:
print("输出错误,请重新输入!")
标签:name time localtime break load end git for http
原文地址:https://www.cnblogs.com/bigsheng15/p/14816392.html