Python自测100题(下)

本文提供了100道Python编程基础练习题,涵盖按位操作、图形绘制、字符串处理、链表操作、列表排序、数字问题等。通过这些题目,你可以深入理解Python的基础语法和常用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

51.题目:学习使用按位与 & 。

程序分析:0&0=0; 0&1=0; 1&0=0; 1&1=1。

print(0&0,0&1,1&0,1&1)

52.题目:学习使用按位或 | 。

程序分析:0|0=0; 0|1=1; 1|0=1; 1|1=1

print(0|0,0|1,1|0,1|1)

53.题目:学习使用按位异或 ^ 。

程序分析:0^0=0; 0^1=1; 1^0=1; 1^1=0

print(0^0,0^1,1^0,1^1)

54.题目:取一个整数a从右端开始的4〜7位。

程序分析:可以这样考虑: (1)先使a右移4位。 (2)设置一个低4位全为1,其余全为0的数。可用(0<<4) (3)将上面二者进行&运算。

a = int(input())
b = a>>4
c = ~(~0 << 4)
d = b&c
print(d)

55.题目:学习使用按位取反~。

a,b = 0,1
print(~a,~b)

56.题目:画图,学画圆形。

import turtle
pen = turtle.Turtle()
pen.circle(50)
print(pen)
turtle.mainloop()

57.题目:画图,学画直线。

import turtle
pen = turtle.Turtle()
pen.forward(100)
print(pen)
turtle.mainloop()

58.题目:画图,学画方形。

import turtle
pen = turtle.Turtle()
pen.forward(50)
pen.right(90)
pen.forward(50)
pen.right(90)
pen.forward(50)
pen.right(90)
pen.forward(50)
print(pen)
turtle.mainloop()

59.题目:画图,综合例子。

程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。

if __name__  == '__main__':
    from Tkinter import *
    canvas = Canvas(width = 300,height = 300,bg = 'green')
    canvas.pack(expand = YES,fill = BOTH)
    x0 = 150
    y0 = 100
    canvas.create_oval(x0 - 10,y0 - 10,x0 + 10,y0 + 10)
    canvas.create_oval(x0 - 20,y0 - 20,x0 + 20,y0 + 20)
    canvas.create_oval(x0 - 50,y0 - 50,x0 + 50,y0 + 50)
    import math
    B = 0.809
    for i in range(16):
        a = 2 * math.pi / 16 * i
        x = math.ceil(x0 + 48 * math.cos(a))
        y = math.ceil(y0 + 48 * math.sin(a) * B)
        canvas.create_line(x0,y0,x,y,fill = 'red')
    canvas.create_oval(x0 - 60,y0 - 60,x0 + 60,y0 + 60)
    

    for k in range(501):
        for i in range(17):
            a = (2 * math.pi / 16) * i + (2 * math.pi / 180) * k
            x = math.ceil(x0 + 48 * math.cos(a))
            y = math.ceil(y0 + 48 + math.sin(a) * B)
            canvas.create_line(x0,y0,x,y,fill = 'red')
        for j in range(51):
            a = (2 * math.pi / 16) * i + (2* math.pi / 180) * k - 1
            x = math.ceil(x0 + 48 * math.cos(a))
            y = math.ceil(y0 + 48 * math.sin(a) * B)
            canvas.create_line(x0,y0,x,y,fill = 'red')
    mainloop()
    #答案来自菜鸟教程

60.题目:计算字符串长度。

a =input()
print(len(a))

61.题目:打印出杨辉三角形(要求打印出10行如下图)。

a = [[1],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[1,1],[1,
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值