1 输入若干成绩,求所有成绩的平均分。每输入一个成绩后询问是否继续输入下一个成绩,回答 yes 就继续输入下一个成绩,回答 no 就停止输入成绩。
scores = []  # 使用列表存放临时数据
while True:
    x = input('score: ')
    try:
        scores.append(float(x))
    except:
        print('Invalid Data')
    while True:
        flag = input('continue?')
        if flag.lower() not in ('yes', 'no'):
            print('yes or no !')
        else:
            break
    if flag.lower() == 'no':
        break
print(sum(scores) / len(scores))

2 编写程序,判断今天是几年的第几天。
import time
date = time.localtime()  # 获取当前日期
print(date)
year, month, day = date[:3]
print(year, month, day)
day_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):  # 判断是否为闰年
    day_month[1] = 29
if month == 1:
    print(day)
else:
    print(sum(day_month[:month - 1]) + day)

3 编写代码,输出由 * 号组成的菱形图案,并且可以灵活控制图案的大小。
def func(n):
    for i in range(n):
        print(' ' * (n - i), end='')
        for j in range(1, 2 * i + 2):
            if j % 2 == 0:
                print(' ', end='')
            else:
                print('*', end='')
        print()
func(6)

def get_rhomb(n):
    i = 1
    while i <= 2 * n - 1:
        print(' ' * abs(n - i), end='')
        j = 1
        while j <= (2 * n - 1) - 2 * abs(n - i):
            if j % 2 == 0:
                print(' ', end='')
            else:
                print('*', end='')
            j += 1
        print()
        i += 1
get_rhomb(6)

def get_rhomb(n):
    i = 1
    while i <= 2 * n - 1:
        print(' ' * abs(n - i), end='')
        j = 1
        while j <= (2 * n - 1) - 2 * abs(n - i):
            if j != 1 and j != (2 * n - 1) - 2 * abs(n - i):
                print(' ', end='')
            else:
                print('*', end='')
            j += 1
        print()
        i += 1
get_rhomb(7)




















