Python练手例子(10)
55、学习使用按位取反~。 程序分析: ~0=1; ~1=0; (1)先使a右移4位。 (2)设置一个低4位全为1,其余全为0的数。可用~(~0<<4) (3)将上面二者进行&运算。 # python3.7 if __name__ == ' __main__ ' : a = 234 b = ~ a print ( ' The a\'s 1 complement is %d ' % b) a = ~ a print ( ' The a\'s 2 complement is %d ' % a) 56、画图,学用circle画圆形。 # python3.7 from tkinter import * if __name__ == ' __main__ ' : canvas = Canvas(width = 800, height = 600, bg = ' purple ' ) canvas.pack(expand = YES, fill = BOTH) k = 1 j = 1 for i in range(0, 26 ): canvas.create_oval( 310 - k, 250 - k, 310 + k, 250 + k, width = 1 ) k += 1 j += 0.3 mainloop() 57、画图,学用line画直线。 # python3.7 from