随笔分类 -  Python

摘要:调用系统模块 from os import system 使用方式: system("cat file.py") 参考:https://geek-docs.com/python/python-examples/using-the-cat-command-in-python.html 阅读全文
posted @ 2023-03-03 22:51 大序列 阅读(23) 评论(0) 推荐(0) 编辑
摘要:Exercise: DESCRIPTION: This time no story, no theory. The examples below show you how to write function accum: Examples: accum("abcd") -> "A-Bb-Ccc-Dd 阅读全文
posted @ 2022-07-11 18:33 大序列 阅读(29) 评论(0) 推荐(0) 编辑
摘要:>> False >> 'No' >>True >> 'Yes' Solutions: 1 def bool_to_word(boolean): return "Yes" if boolean else "No" 2 def bool_to_word(boolean): return ['No', 阅读全文
posted @ 2022-07-10 14:18 大序列 阅读(19) 评论(0) 推荐(0) 编辑
摘要:判断 奇数 偶数: Solution: 1 def even_or_odd(number): return 'Even' if number % 2 == 0 else 'Odd' 2 def even_or_odd(number): return ['Even', 'Odd'][number % 阅读全文
posted @ 2022-07-10 10:58 大序列 阅读(15) 评论(0) 推荐(0) 编辑
摘要:Solution: def rps(p1, p2): dict_wins = {('rock', 'scissors') : 'Player 1 won!', ('rock', 'paper'):'Player 2 won!', ('scissors', 'rock') : 'Player 2 wo 阅读全文
posted @ 2022-07-07 21:35 大序列 阅读(22) 评论(0) 推荐(0) 编辑
摘要:Solition: def number(bus_stops): return sum([i[0] - i[1] for i in bus_stops]) def number(bus_stops): return sum(on - off for on, off in bus_stops) 阅读全文
posted @ 2022-07-06 19:08 大序列 阅读(14) 评论(0) 推荐(0) 编辑
摘要:描述: 你的函数有两个参数: 当前父亲的年龄(岁) 儿子现在的年龄(岁) 计算多少年前父亲的年龄是儿子的两倍(或多少年后他将是儿子的两倍)。 Solution: def twice_as_old(f, s): return abs(f - s * 2) :abs(x) 取数值绝对值 阅读全文
posted @ 2022-07-06 18:29 大序列 阅读(33) 评论(0) 推荐(0) 编辑
摘要:DESCRIPTION: Who remembers back to their time in the schoolyard, when girls would take a flower and tear its petals, saying each of the following phra 阅读全文
posted @ 2022-07-06 16:06 大序列 阅读(187) 评论(0) 推荐(0) 编辑
摘要:Exercise: 给定一个由 1 和 0 组成的数组,将等效的二进制值转换为整数。 例如:[0, 0, 0, 1]被视为是0001的二进制==>1。 例子: Testing: [0, 0, 0, 1] ==> 1 Testing: [0, 0, 1, 0] ==> 2 Testing: [0, 1 阅读全文
posted @ 2022-07-06 14:12 大序列 阅读(24) 评论(0) 推荐(0) 编辑
摘要:Exercise: Solution: def descending_order(num): return eval(''.join(sorted(str(num), reverse=True))) def descending_order(num): return int(''.join(sort 阅读全文
posted @ 2022-07-05 20:25 大序列 阅读(22) 评论(0) 推荐(0) 编辑
摘要:In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out. E 阅读全文
posted @ 2022-07-05 19:28 大序列 阅读(15) 评论(0) 推荐(0) 编辑
摘要:Exercise: 故事: Bob 是一名公交车司机。然而,他在城市居民中非常受欢迎。有这么多乘客想上他的巴士,他有时不得不面对巴士上没有足够空间的问题!他希望你编写一个简单的程序,告诉他是否能够容纳所有乘客。 任务概述: 您必须编写一个接受三个参数的函数: cap是巴士可以容纳的人数,不包括司机。 阅读全文
posted @ 2022-07-05 18:15 大序列 阅读(27) 评论(0) 推荐(0) 编辑
摘要:Exercise: In a factory a printer prints labels for boxes. For one kind of boxes the printer has to use colors which, for the sake of simplicity, are n 阅读全文
posted @ 2022-07-04 21:48 大序列 阅读(56) 评论(0) 推荐(0) 编辑
摘要:exercise: Solution: def paperwork(n, m): return m*n if m>=0 and n>=0 else 0 def paperwork(n, m): return max(m,0) * max(n,0) 阅读全文
posted @ 2022-07-04 19:04 大序列 阅读(19) 评论(0) 推荐(0) 编辑
摘要:Exercise: 奇偶判定:给两个整数判断是否是一奇数一偶数 solution: def lovefunc( flower1, flower2 ): return sum([flower1,flower2]) % 2 >0 :sum()函数 :% 求余数 阅读全文
posted @ 2022-07-04 15:44 大序列 阅读(51) 评论(0) 推荐(0) 编辑
摘要:Exercise: 单词首字母大写(刷题遇到title()失效) solution: def case(string): return ' '.join(word.capitalize() for word in string.split()) #先用split()函数 切片 字符串 #再capit 阅读全文
posted @ 2022-07-03 20:54 大序列 阅读(20) 评论(0) 推荐(0) 编辑
摘要:参考:Python - ^ 在正则表达式中的作用 ^在正则表达式中有两个作用,一是表达以什么开头,二是表达对什么取反。有时候经常傻傻的分不清楚,接下来给大家详细介绍该怎么用这个^准备一个python文件test.py,借用re.search函数举例说明 # coding=utf-8 import r 阅读全文
posted @ 2022-07-03 16:43 大序列 阅读(1586) 评论(0) 推荐(0) 编辑
摘要:exercise: Your task is to create the functionisDivideBy (or is_divide_by) to check if an integer number is divisible by both integers a and b. A few c 阅读全文
posted @ 2022-07-03 12:20 大序列 阅读(11) 评论(0) 推荐(0) 编辑
摘要:exercis: Solution: def basic_op(operator, value1, value2): return eval(str(value1) + operator + str(value2))#math模块eval()执行字符串表达式 阅读全文
posted @ 2022-07-02 23:38 大序列 阅读(16) 评论(0) 推荐(0) 编辑
摘要:Exercise: Solution: def sum_array(arr): if arr: #判断序列是否 为 空 :if arr > TRUE 不是空序列 if len(arr) > 2: # 序列是否存在两个以上的 元素 arr.remove(max(arr)) arr.remove(min 阅读全文
posted @ 2022-06-30 21:02 大序列 阅读(37) 评论(0) 推荐(0) 编辑