在制作程序以显示骰子脸部的视觉时,我正在测试它并且似乎有效,除了在每个骰子脸部之后没有打印。 代码是:
def visual (x):
types= ['+-------+','| |','| * |','| * * |']
if x == 1:
print (types[0])
print (types[1])
print (types[2])
print (types[1])
print (types[0])
if x == 2:
print (types[0])
print (types[2])
print (types[1])
print (types[2])
print (types[0])
if x == 3:
print (types[0])
print (types[2])
print (types[2])
print (types[2])
print (types[0])
if x == 4:
print (types[0])
print (types[3])
print (types[1])
print (types[3])
print (types[0])
if x == 5:
print (types[0])
print (types[3])
print (types[2])
print (types[3])
print (types[0])
if x == 6:
print (types[0])
print (types[3])
print (types[3])
print (types[3])
print (types[0])
def main():
x = [1,2,3,4,5,6]
for a in x:
print (a)
print (visual(a))
main()
它返回:
1
+-------+
| |
| * |
| |
+-------+
None
2
+-------+
| * |
| |
| * |
+-------+
None
3
+-------+
| * |
| * |
| * |
+-------+
None
4
+-------+
| * * |
| |
| * * |
+-------+
None
5
+-------+
| * * |
| * |
| * * |
+-------+
None
6
+-------+
| * * |
| * * |
| * * |
+-------+
None
正如你所看到的那样,没有'每个骰子脸被打印后出现。它显然必须在for循环中,但我不知道是什么导致它。
答案 0 :(得分:2)
您无需print (visual(a))
。您只需致电visual(a)
。
print (visual(a))
将打印visual(a)
的返回值。由于它不会返回任何内容,因此将打印None
。