1 ''' 2 #华氏转换摄氏 3 f = float(input('清输入华氏温度:')) 4 c = (f - 32) / 1.8 5 print('%.1f华氏度 = %.1f摄氏度' % (f, c)) 6 ''' 7 8 ''' 9 #使用变量保存数据并进行运算 10 a = 123 11 b = 321 12 print(a + b) 13 print(a - b) 14 print(a * b) 15 print(a / b) 16 print(a // b)#向下取整除 17 print(a ** b)#幂 18 print(a % b)#模除 19 ''' 20 21 ''' 22 #使用type()函数检查数据的类型 23 a = 12 24 b = 12.44 25 c = 12 + 6j 26 d = '刘诗琪我喜欢你啊' 27 e = True 28 print(type(a))#int 29 print(type(b))#float 30 print(type(c))#complex 31 print(type(d))#str 32 print(type(e))#bool 33 ''' 34 35 ''' 36 #使用input()函数获取键盘输入(字符串) 37 #使用int()函数将输入的字符串转换成整数 38 #使用print()函数输出带占位符的字符串 39 a = int(input(' a = ')) 40 b = int(input(' b = ')) 41 print('%d + %d = %d' % (a, b, a + b)) 42 print('%d - %d = %d' % (a, b, a - b)) 43 print('%d * %d = %d' % (a, b, a * b)) 44 print('%d / %d = %f' % (a, b, a / b)) 45 print('%d // %d = %d' % (a, b, a // b)) 46 print('%d %% %d = %d' % (a, b, a % b)) 47 print('%d ** %d = %d' % (a, b, a ** b)) 48 #上面的print函数中输出的字符串使用了占位符语法,其中%d是整数的占位符,%f是小数的占位符,%%表示百分号(由于百分号表明了占位符,因此带占位符的字符串中要表示百分号必须写成%%),字符串以后的%后面跟的变量值会替换掉占位符而后输出到终端中 49 ''' 50 51 ''' 52 #赋值运算符和复合赋值运算符 53 a = 10 54 b = 3 55 a += b#a = a + b 56 a *= a + 2#a = a * (a + 2) 57 print(a) 58 ''' 59 60 ''' 61 #比较、逻辑和身份运算符的使用 62 flag0 = 1 == 1 63 flag1 = 3 > 2 64 flag2 = 2 < 1 65 flag3 = flag1 and flag2 66 flag4 = flag1 or flag2 67 flag5 = not (1 != 2) 68 print('flag0 =', flag0) 69 print('flag1 =', flag1) 70 print('flag2 =', flag2) 71 print('flag3 =', flag3) 72 print('flag4 =', flag4) 73 print('flag5 =', flag5) 74 print(flag1 is True) 75 print(flag2 is not False) 76 ''' 77 78 ''' 79 #输入半径计算圆的周长和面积 80 import math 81 radius = float(input('请输入圆的半径:')) 82 permeter = 2 * math.pi * radius 83 area = math.pi * radius ** 2 84 print('周长:%.2f' % permeter) 85 print('面积:%.2f' % area) 86 ''' 87 88 89 #输入年份判断是否是闰年 90 year = int(input('请输入年份: ')) 91 is_year = (year % 4 == 0 and year % 100 != 0) or \ 92 year % 400 ==0 93 print(is_year)
1 """ 2 用Python的turtle模块绘制国旗 3 """ 4 import turtle 5 6 7 def draw_rectangle(x, y, width, height): 8 """绘制矩形""" 9 turtle.goto(x, y) 10 turtle.pencolor('red') 11 turtle.fillcolor('red') 12 turtle.begin_fill() 13 for i in range(2): 14 turtle.forward(width) 15 turtle.left(90) 16 turtle.forward(height) 17 turtle.left(90) 18 turtle.end_fill() 19 20 21 def draw_star(x, y, radius): 22 """绘制五角星""" 23 turtle.setpos(x, y) 24 pos1 = turtle.pos() 25 turtle.circle(-radius, 72) 26 pos2 = turtle.pos() 27 turtle.circle(-radius, 72) 28 pos3 = turtle.pos() 29 turtle.circle(-radius, 72) 30 pos4 = turtle.pos() 31 turtle.circle(-radius, 72) 32 pos5 = turtle.pos() 33 turtle.color('yellow', 'yellow') 34 turtle.begin_fill() 35 turtle.goto(pos3) 36 turtle.goto(pos1) 37 turtle.goto(pos4) 38 turtle.goto(pos2) 39 turtle.goto(pos5) 40 turtle.end_fill() 41 42 43 def main(): 44 """主程序""" 45 turtle.speed(12) 46 turtle.penup() 47 x, y = -270, -180 48 # 画国旗主体 49 width, height = 540, 360 50 draw_rectangle(x, y, width, height) 51 # 画大星星 52 pice = 22 53 center_x, center_y = x + 5 * pice, y + height - pice * 5 54 turtle.goto(center_x, center_y) 55 turtle.left(90) 56 turtle.forward(pice * 3) 57 turtle.right(90) 58 draw_star(turtle.xcor(), turtle.ycor(), pice * 3) 59 x_poses, y_poses = [10, 12, 12, 10], [2, 4, 7, 9] 60 # 画小星星 61 for x_pos, y_pos in zip(x_poses, y_poses): 62 turtle.goto(x + x_pos * pice, y + height - y_pos * pice) 63 turtle.left(turtle.towards(center_x, center_y) - turtle.heading()) 64 turtle.forward(pice) 65 turtle.right(90) 66 draw_star(turtle.xcor(), turtle.ycor(), pice) 67 # 隐藏海龟 68 turtle.ht() 69 # 显示绘图窗口 70 turtle.mainloop() 71 72 73 if __name__ == '__main__': 74 main()
1 #!/usr/bin/env python 2 # -*-coding: UTF-8-*- 3 #画正方形 4 import turtle 5 6 turtle.pensize(4) 7 turtle.pencolor('red') 8 9 turtle.forward(100) 10 turtle.right(90) 11 turtle.forward(100) 12 turtle.right(90) 13 turtle.forward(100) 14 turtle.right(90) 15 turtle.forward(100) 16 17 turtle.mainloop()
今天算是屁股坐住了,码了一点,但效率不高,重复的知识也蛮多,明天继续,go on, go on!!!python
🎑🏞🌅🌄🌠🎇🌁🌌🌉🌃🏙🌆函数