Python经典入门100题 (51-60题)

题目地址: https://blog.csdn.net/weixin_41084236/article/details/81564963
转载请标注: https://blog.csdn.net/qq_43582207
代码编写过程中是自己发挥的,只代表其中一种方法,仅供学习参考
运行版本:Python3.7
作者:My apologize


实例054题,是借鉴这里的》》》https://blog.csdn.net/weixin_41084236/article/details/81564963

明日会专门出一期详细讲解python按位操作

实例051:按位与

# 实例051:按位与
# 题目 学习使用按位与 &

print(1&4);print(bin(1&4))

print(10001&10010)

print(212&215)

实例052:按位或

# 实例052:按位或
# 题目 学习使用按位或 | 。
print(bin(1)); print(bin(4))

print(1|4);print(bin(1|4));

实例053:按位异或

# 实例053:按位异或
# 题目 学习使用按位异或 ^ 。

print(0^0)
print(100^1111)
a=10
print(a^3)
print(a^3^7)

实例054:位取反、位移动

# 实例054:位取反、位移动
# 题目 取一个整数a从右端开始的4〜7位。
a=int(input('输入一个数字: '))
b=0                 #     0
b=~b                #     1
b=b<<4              # 10000
b=~b                #  1111
c=a>>4
d=c&b
print('a:',bin(a))
print('b:',bin(b))
print('c:',bin(c))
print('d:',bin(d))

实例055:按位取反

# 实例055:按位取反
# 题目 学习使用按位取反~。
print(55)
print(~55)
print(~~55)
print(bin(55), bin(~55))

实例056:画圈

# 实例056:画圈
# 题目 画图,学用circle画圆形。
import turtle
turtle.circle(50)


实例057:画线

# 实例057:画线
# 题目 画图,画直线。
import turtle

turtle.pensize(10)
turtle.fd(200)

实例058:画矩形

# 实例058:画矩形
# 题目 画图,学画方形。

import turtle
turtle.goto(100,0)
turtle.goto(100,-100)
turtle.goto(0,-100)
turtle.goto(0,0)

实例059:画图(丑)

# 实例059:画图(丑)
# 题目 画图,综合例子。

import turtle

turtle.fd(200)
turtle.right(90)
turtle.fd(250)
turtle.pu()
turtle.goto(200,-125)
turtle.pd()
turtle.goto(0,-125)
turtle.pu()
turtle.goto(100,-250)
turtle.pd()
turtle.goto(100,0)
turtle.pu()
turtle.goto(-50 ,-250)
turtle.pd()
turtle.goto(300,-250)

turtle.done()

实例060:字符串长度

# 实例060:字符串长度
# 题目 计算字符串长度。

a = 'dhiuehdu 15__67'
print(len(a))

=====================================================

如果觉得我的文章对你有帮助的,麻烦动动你的小手,关注支持一波!谢谢啦

########################################################

猜你喜欢

转载自blog.csdn.net/qq_43582207/article/details/107619360