width_top = 2*6-1; width_di = 2*5-1; for i inrange(1,7): str = '*'*(2*i-1) print(str.center(width_top,' ')) for i inrange(5,-1,-1): str = '*' * (2 * i - 1) print(str.center(width_top,' '))
题目二
输入一个年份,判断并输出该年份是否为闰年。。
代码
1 2 3 4 5 6
date = eval(input("请输入一个年份:")) # print(date) if (date%100!=0and date%4==0) or (date%400==0): print("{}年是闰年".format(date)) else: print("{}年不是闰年".format(date))
for i instr: if48<=ord(i)<=57or97<=ord(i)<=122: word = word+i elif65<=ord(i)<=90: i = chr(ord(i)+32) word = word+i else: if word == "": continue else: word_value = {word: 1} if (word in word_dic.keys()): word_dic[word] += 1 word = "" else: word_dic.update(word_value) word = "" sorted_word = sorted(word_dic.items(),key=lambda d:d[0]) # print(sorted_word) for key,value in sorted_word: print("{}:{}".format(key,value))