摘要: from turtle import * def square(size=50, rgb='orange'): '''绘制正方形 参数size指定边长 参数rgb指定画笔颜色 如果没有给参数,采用默认值''' pencolor(rgb) for i in range(4): fd(size) lef 阅读全文
posted @ 2022-06-14 11:54 思杰 阅读(18) 评论(1) 推荐(0) 编辑
摘要: class User: def __init__(self, name, password='111111', status='1'): # 构造新账户 self.name = name self.password = password self.status = status def info(s 阅读全文
posted @ 2022-06-08 09:57 思杰 阅读(10) 评论(1) 推荐(0) 编辑
摘要: 3 def is_valid(x): a,b,c = set(x),set("1234567890X"),set() if (a|b)-b!=c or len(x)!=18:return False return True with open('data3_id.txt','r',encoding= 阅读全文
posted @ 2022-05-26 11:06 思杰 阅读(20) 评论(3) 推荐(0) 编辑
摘要: with open('data1_1.txt', 'r', encoding='utf-8') as f: n=0 for line in f: # 逐行遍历处理 if line.strip('\n') =='': continue n+=1 print(f'共{n}行') with open('d 阅读全文
posted @ 2022-05-17 15:14 思杰 阅读(22) 评论(3) 推荐(0) 编辑
摘要: task1.py print(sum) sum = 42 print(sum) def inc(n): sum = n+1 print(sum) return sum sum = inc(7) + inc(7) print(sum) 源码中,共有4处有python语句 print(sum) (lin 阅读全文
posted @ 2022-05-11 14:31 思杰 阅读(21) 评论(2) 推荐(0) 编辑
摘要: #task1.py import random print('用列表存储随机整数: ') ls = [random.randint(1, 100) for i in range(5)] print(ls) print('\n用集合存储随机整数: ') s1 = {random.randint(1,1 阅读全文
posted @ 2022-04-25 23:50 思杰 阅读(28) 评论(4) 推荐(0) 编辑
摘要: 1. 实验任务1# 基础操作练习: 列表及列表推导式、格式化、类型转换 x = list(range(10)) print('整数输出1: ', end = '') for i in x: print(i, end=' ') print('\n整数输出2: ', end = '') for i in 阅读全文
posted @ 2022-04-12 16:39 思杰 阅读(26) 评论(2) 推荐(0) 编辑
摘要: # print输出的几种用法 # 用法1:用于输出单个字符串或单个变量 print('hey, u') # 用法2: 用于输出多个数据项,用逗号分隔 print('hey', ' u') x,y,z = 1,2,3 print(x, y, z) # 用法3: 用户混合字符串和变量值 print('x 阅读全文
posted @ 2022-03-29 12:26 思杰 阅读(17) 评论(4) 推荐(0) 编辑
摘要: 1 print("hi,python,I'm trying") 2 3 a,b = eval(input('Enter two numbers: ')) 4 print(f'a = {a},b = {b}') 阅读全文
posted @ 2022-03-23 22:25 思杰 阅读(23) 评论(0) 推荐(0) 编辑