标签:编程 grid and apple for 字符 源代码 网格 pytho
Python编程快速上手实践项目题目,欢迎指证与优化!spam = [‘apples‘, ‘bananas‘, ‘tofu‘, ‘cats‘]
for i in range(len(spam)-1):
print(spam[i],end = ",")
print ("and" + " " + spam[len(spam)-1])
运行结果:apples,bananas,tofu,and cats
grid = [[‘.‘, ‘.‘, ‘.‘, ‘.‘, ‘.‘, ‘.‘],
[‘.‘, ‘O‘, ‘O‘, ‘.‘, ‘.‘, ‘.‘],
[‘O‘, ‘O‘, ‘O‘, ‘O‘, ‘.‘, ‘.‘],
[‘O‘, ‘O‘, ‘O‘, ‘O‘, ‘O‘, ‘.‘],
[‘.‘, ‘O‘, ‘O‘, ‘O‘, ‘O‘, ‘O‘],
[‘O‘, ‘O‘, ‘O‘, ‘O‘, ‘O‘, ‘.‘],
[‘O‘, ‘O‘, ‘O‘, ‘O‘, ‘.‘, ‘.‘],
[‘.‘, ‘O‘, ‘O‘, ‘.‘, ‘.‘, ‘.‘],
[‘.‘, ‘.‘, ‘.‘, ‘.‘, ‘.‘, ‘.‘]]
for j in range (len (grid[0])):
for i in range (len(grid)):
print (grid[i][j],end="")
print ("\r")
运行结果:
..OO.OO..
.OOOOOOO.
.OOOOOOO.
..OOOOO..
...OOO...
....O....
标签:编程 grid and apple for 字符 源代码 网格 pytho
原文地址:https://blog.51cto.com/xxy12345/2425048