13、99乘法表
def print99(): for i in range(1,10):
for j in range(1,i + 1):
print("%d x %d = %d" % (j,i,j * i),end = " ")
print("")
print99()
14、求两个数的最大公约数
num1 = int(input("请输入第一个数"))
num2 = int(input("请输入第二个数"))
num3 = min(num1,num2)
i = 1 sum = 1 for i in range(1,num3):
if num1 % i == 0 and num2 % i == 0:
sum *= i
num1 /= i
num2 /= i
for i in range(1,num3):
if num1 % i == 0 and num2 % i == 0:
sum *= i
num1 /= i
num2 /= i
print(sum)
15、输入一个字符串,将字符串中的大写字母转成小写字母,小写转大写
s1 = input("请输入一个字符串")
s10 = "" for i in range(len(s1)):
s2 = ord(s1[i])
if s2 < 91:
s3 = chr(s2 + 32)
s10 += s3
else:
s3 = chr(s2 - 32)
s10 += s3
print(s10)
16、随机生成一个6位数的验证码
import random
list1 = [0,1,2,3,4,5,6,7,8,9,'a',"b","c",'d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t']
list2 = [] for i in range(6):
list2.append(random.choice(list1))
print(list2)
17、画图(正方形、矩形、五角星、奥运五环、围棋棋盘、国际象棋棋盘)
import turtle turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(100) turtle.forward(100)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(100)
turtle.right(90)
turtle.forward(200)
turtle.hideturtle()
turtle.done() turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.done() turtle.speed(10)
turtle.pensize(5)
turtle.pencolor("black")
turtle.circle(100)
turtle.up()
turtle.forward(200)
turtle.down()
turtle.pencolor("red")
turtle.circle(100)
turtle.up()
turtle.goto(-200,0)
turtle.down()
turtle.pencolor("blue")
turtle.circle(100)
turtle.up()
turtle.goto(-100,-120)
turtle.down()
turtle.pencolor("yellow")
turtle.circle(100)
turtle.up()
turtle.goto(100,-120)
turtle.down()
turtle.pencolor("green")
turtle.circle(100)
turtle.done() turtle.speed(10)
turtle.up()
turtle.goto(-300,300)
turtle.down()
turtle.goto(300,300)
turtle.goto(300,-300)
turtle.goto(-300,-300)
turtle.goto(-300,300) for i in range(-300,300,30):
turtle.up()
turtle.goto(i + 30, 300)
turtle.down()
turtle.goto(i + 30, -300)
turtle.up()
turtle.goto(i + 60, -300)
turtle.down()
turtle.goto(i + 60, 300)
if i == 240:
break turtle.up()
turtle.goto(-300,300) for i in range(300,-300,-30):
turtle.up()
turtle.goto(-300, i -30)
turtle.down()
turtle.goto(300, i -30)
turtle.up()
turtle.goto(300, i -60)
turtle.down()
turtle.goto(-300, i -60)
if i == -240:
break turtle.up()
turtle.goto(-210, -210)
turtle.down()
turtle.begin_fill()
turtle.fillcolor("black")
turtle.circle(2)
turtle.end_fill()
turtle.done() turtle.speed(10)
turtle.up()
turtle.goto(-80,80)
turtle.down()
turtle.goto(80,80)
turtle.goto(80,-80)
turtle.goto(-80,-80)
turtle.goto(-80,80) y = 80 for d in range(80,-80,20):
for i in range(-80,80,20):
turtle.goto(i,80)
turtle.begin_fill()
turtle.fillcolor("white")
turtle.goto(i + 20 ,y)
turtle.goto(i + 20,y -20)
turtle.goto(i,y -20)
turtle.goto(i,y)
turtle.end_fill
turtle.goto(i, 80)
turtle.begin_fill()
turtle.fillcolor("red")
turtle.goto(i + 40, y)
turtle.goto(i + 40, y - 20)
turtle.goto(i, y - 20)
turtle.goto(i, y)
turtle.end_fill()
if i == 40:
break turtle.goto(-80,d)
turtle.done()