随笔分类 - python学习
python看的是B站小甲鱼的,感觉还不错。如何看了子木的实例操作,自己也跟着敲了一遍,对所学的更深的巩固
摘要:import os filename = 'student.txt' def main(): while True: menum() choice = int(input("请选择对应数字:")) if choice in [0, 1, 2, 3, 4, 5, 6, 7]: if choice ==
阅读全文
摘要:任务一: import time def show_info(): print('输入提示数字,执行相应的操作:0.退出 1.查看登录日志') # 记录日志 def write_logininfo(username): with open('log.txt', 'a')as file: s = f'
阅读全文
摘要:任务一: import prettytable as pt # 显示座席 def show_ticket(row_num): tb = pt.PrettyTable() tb.field_names = ['行号', '座位1 ', '座位2', '座位3', '座位4', '座位5'] for i
阅读全文
摘要:任务一: class Instrument(): def make_sound(self): pass class Erhu(Instrument): def make_sound(self): print('二胡在演奏') class Piano(Instrument): def make_sou
阅读全文
摘要:任务一: import math class Circle(object): def __init__(self, r): self.r = r def get_area(self): return math.pi*math.pow(self.r, 2) def get_perimeter(self
阅读全文
摘要:任务一: try: score = int(input('请输入你的分数:')) if 0 <= score <= 100: print('分数为:', score) else: raise Exception('分数不正确') except Exception as e: print(e) 任务二
阅读全文
摘要:任务一: def calc(a, b, op): if op == "+": return add(a, b) elif op == "-": return sub(a, b) elif op == '*': return mul(a, b) elif op == "/": if b!= 0: re
阅读全文
摘要:任务一: # 统计指定字符出现的次数 def get_count(s, ch): count = 0 for item in s: if ch.upper() == item or ch.lower() == item: count += 1 return count if __name__ ==
阅读全文
摘要:任务一: coffee_name = ('蓝山', '卡布其尔', '拿铁', '皇家咖啡', '女五咖啡', '美丽与哀愁') print('您好!欢迎光临小(>^ω^<)喵咖啡屋') print('本店经营的咖啡有:') # index获取元组当中的元素索引,item获取元组当中的元素内容 fo
阅读全文
摘要:任务一: # 创建星座的列表 constellation = ['白羊座', '金牛座', '双子座', '巨蟹座', '狮子座', '处女座', '天秤座', '天蝎座', '射手座', '摩羯座', '水瓶座', '双鱼座'] # 创建性格列表 nature = ['积极乐观', '固执内向',
阅读全文
摘要:任务一: year = [83, 89, 83, 94, 85, 00, 98] print('原列表:', year) for index, value in enumerate(year): # print(index, value) if str(value) != '0': year[ind
阅读全文
摘要:任务一: # 代表了a的ASCII值 x = 97 for _ in range(1, 27): print(chr(x), '➝➝➝➝➝', x) x += 1 print(' ') x = 97 while x< 123: print(chr(x), '➝➝➝➝➝', x) x += 1 任务二
阅读全文
摘要:任务一: # 模拟支付密码的验证 pwd = input('支付宝支付密码:') if pwd.isdigit():# isdigit判断支付密码是否全部为数字 print('支付数据合法') else: print('支付数字不合法,支付密码只能是数据') print(' ') print('支付
阅读全文
摘要:任务一: def fun(): num = int(input("请输入一个十进制的整数:")) print(num, '的二进制数为:', bin(num)) # 第一种写法,使用了个数可变的位置参数 print(str(num)+"的二进制数为:"+bin(num)) # 第二种写法,使用“+”
阅读全文
摘要:任务一: book_name = 'Java程序设计程序' publish = '西安电子科技大学出版社' pub_date = "2019-02-02" price = 56.8 print('▶→→→→→→→→→→→→→→→→→→→◀') print('▷\t\t《', book_name, '
阅读全文
摘要:任务一: # 一、①使用print方式进行输出(输出的目的地是文件) fp = open('D:/test.txt', 'w') print("奋斗成就更好的你", file=fp) fp.close() 任务二: # ②使用文件读写操作 with open('D:/test1.txt', 'w')
阅读全文
摘要:import math class Shape: def __init__(self, name, area, perimeter): self.name = name self.area = area self.perimeter = perimeter def cal_area(self): p
阅读全文
摘要:封装 class Turtle: head = 1 eyes = 2 leg = 4 shell = True def crawl(self): print("人们总抱怨我动作慢吞吞的,殊不知如不积跬步,无以至千里的道理。") def run(self): print("虽然我行动很慢,但如果遇到危
阅读全文
摘要:求一个数的阶乘 # 迭代方法实现 def factIter(n): result = n for i in range(1, n): result *= i return result print(factIter(10)) # 递归方法实现 def funC(n): if n == 1: retu
阅读全文
摘要:创建和调用函数 # I Love You # I Love You # I Love You def myfunc(): for i in range(3): print("I Love You") myfunc() 函数的参数 # I Love python # I Love python # I
阅读全文