Python编程快速上手——让繁琐工作自动化第四章实践题

版权声明:作者:Newbei~ 来源:CSDN 原文:https://blog.csdn.net/weixin_44078216 版权声明:本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/weixin_44078216/article/details/85268189

##4.10.1

def hanshu1(list2):
    str1 = list2[0] + ', ' + 'and ' + list2[1]
    print(str1)

def hanshu2(list2):
    str1 = list2[0]
    str2 = ', ' + 'and ' + list2[-1]
    for a in range(1,(len(list2)-1)):
        str1 = str1 + ', ' + list2[a]
    str1 = str1 + str2
    print(str1)

i = 1
list1 = []
while True:
    print(f"请输入列表的第{i}个参数: ")
    canshu = input()
    if canshu == '':
        break
    else:
        list1.append(canshu)
        i += 1
if len(list1) == 0:
    exit
elif len(list1) == 1:
    print(list1[0])
elif len(list1) == 2:
    hanshu1(list1)
else:
    hanshu2(list1)

##4.10.1

grid = [['.', '.', '.', '.', '.', '.'],
        ['.', '0', '0', '.', '.', '.'],
        ['0', '0', '0', '0', '.', '.'],
        ['0', '0', '0', '0', '0', '.'],
        ['.', '0', '0', '0', '0', '0'],
        ['0', '0', '0', '0', '0', '.'],
        ['0', '0', '0', '0', '.', '.'],
        ['.', '0', '0', '.', '.', '.'],
        ['.', '.', '.', '.', '.', '.']]

str1 = ''
for a in range(0,6):
    for b in range(0,9):
        str1 = grid[b][a]
        print(str1, end='')
    print()

猜你喜欢

转载自blog.csdn.net/weixin_44078216/article/details/85268189