摘要: code def g_h_filter(data,x0,dx,g,h,dt=1.0,pred=None): x=x0 results=[] for z in data: x_est=x+(dx*dt) dx=dx if pred is not None: pred.append(x_est) res 阅读全文
posted @ 2020-05-03 15:25 anobscureretreat 阅读(880) 评论(0) 推荐(0)
摘要: code # 通过用户输入数字计算阶乘 # 获取用户输入的数字 num = 4 factorial = 1 # 查看数字是负数,0 或 正数 if num < 0: print("抱歉,负数没有阶乘") elif num == 0: print("0 的阶乘为 1") else: for i in 阅读全文
posted @ 2020-05-03 15:22 anobscureretreat 阅读(296) 评论(0) 推荐(0)
摘要: code # 获取用户输入十进制数 dec = 255 print("十进制数为:", dec) print("转换为二进制为:", bin(dec)) print("转换为八进制为:", oct(dec)) print("转换为十六进制为:", hex(dec)) 阅读全文
posted @ 2020-05-03 15:21 anobscureretreat 阅读(241) 评论(0) 推荐(0)
摘要: code # 最简单的 print(max(1, 2)) print(max('a', 'b')) # 也可以对列表和元组使用 print(max([1,2])) print(max((1,2))) # 更多实例 print("80, 100, 1000 最大值为: ", max(80, 100, 阅读全文
posted @ 2020-05-03 15:20 anobscureretreat 阅读(1756) 评论(0) 推荐(0)
摘要: code # Python 判断奇数偶数 # 如果是偶数除于 2 余数为 0 # 如果余数为 1 则为奇数 num = 34 if (num % 2) == 0: print("{0} 是偶数".format(num)) else: print("{0} 是奇数".format(num)) 阅读全文
posted @ 2020-05-03 15:18 anobscureretreat 阅读(3409) 评论(0) 推荐(0)
摘要: code def is_number(s): try: float(s) return True except ValueError: pass return False # 测试字符串和数字 print(is_number('foo')) # False print(is_number('1')) 阅读全文
posted @ 2020-05-03 15:17 anobscureretreat 阅读(461) 评论(0) 推荐(0)
摘要: code num = 4 if num > 0: print("正数") elif num == 0: print("零") else: print("负数") # 内嵌 if 语句 if num >= 0: if num == 0: print("零") else: print("正数") els 阅读全文
posted @ 2020-05-03 15:15 anobscureretreat 阅读(482) 评论(0) 推荐(0)
摘要: code # 用户输入 x = 123 y = 456 # 创建临时变量,并交换 temp = x x = y y = temp print('交换后 x 的值为: {}'.format(x)) print('交换后 y 的值为: {}'.format(y)) # 不使用临时变量 x,y = y,x 阅读全文
posted @ 2020-05-03 15:13 anobscureretreat 阅读(249) 评论(0) 推荐(0)
摘要: code # 用户输入摄氏温度 celsius = 34.43 # 计算华氏温度 fahrenheit = (celsius * 1.8) + 32 print('%0.1f 摄氏温度转为华氏温度为 %0.1f ' %(celsius,fahrenheit)) 阅读全文
posted @ 2020-05-03 15:12 anobscureretreat 阅读(1470) 评论(0) 推荐(0)
摘要: code # 生成 0 ~ 9 之间的随机数 # 导入 random(随机数) 模块 import random print(random.randint(0,9)) 阅读全文
posted @ 2020-05-03 15:11 anobscureretreat 阅读(235) 评论(0) 推荐(0)