python 代码
这个,千万别截图,还得输入一遍,累死。我没看出来使用两重循环的需要。另外,我默认3X3了,其实可以更加智能一点,判断任意nxn的。
C:\》ttt.py
’X’ wins (horizontal).
Draw.
’O’ wins (diagonal).
’X’ wins (vertical).
代码:
def ttt(s):
for i in range(3):
label=’horizontal’
if s[i]==s[i] and s[i]==s[i]:
return “’%s’ wins (%s).“%(s[i],label)
for i in range(3):
label=’vertical’
if s[i]==s[i] and s[i]==s[i]:
return “’%s’ wins (%s).“%(s[i],label)
label=“diagonal“
if s==s and s==s:
return “’%s’ wins (%s).“%(s,label)
if s==s and s==s:
return “’%s’ wins (%s).“%(s,label)
return “Draw.“
print ttt([(’X’, ’ ’, ’O’),
(’ ’, ’O’, ’O’),
(’X’, ’X’, ’X’) ])
print ttt([(’X’, ’O’, ’X’),
(’O’, ’X’, ’O’),
(’O’, ’X’, ’O’) ])
print ttt([(’X’, ’O’, ’O’),
(’X’, ’O’, ’ ’),
(’O’, ’X’, ’ ’) ])
print ttt([(’X’, ’O’, ’X’),
(’O’, ’O’, ’X’),
(’O’, ’X’, ’X’) ])
用Python matplotlib 怎么画风向玫瑰图 能给出程序的
import numpy as np
import matplotlib.pyplot as plt
N = 20
theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)
radii = 10 * np.random.rand(N)
width = np.pi / 4 * np.random.rand(N)
ax = plt.subplot(111, projection=’polar’)
bars = ax.bar(theta, radii, width=width, bottom=0.0)
# Use custom colors and opacity
for r, bar in zip(radii, bars):
bar.set_facecolor(plt.cm.jet(r / 10.))
bar.set_alpha(0.5)
plt.show()
差不多上面代码的原理,具体的自己照着官方文档改
python脚本开头的from Tkinter import *是什么意思
这是Python导入库文件的语法:
1.
from
Tkinter的意思就是导入Tkinter,它是一个库,也可以简单称之为类;
2.
import
*的意思是导入库中所有的类,函数,变量等等信息,这样在调用相关函数或者变量的时候,就不用加Tkinter前缀了。
-python装逼代码大全