##############################################################################
# codecademy python 5.5
# Define a function factorial that takes an integer x as input.
# Calculate and return the factorial of that number.
# def digit_sum(x):
# mul = 1
# for i in range(1,x+1):
# mul = i*mul
# print(mul)
# digit_sum(6)
##############################################################################
# codecademy python 5.6
# Define a function called is_prime that takes a number x as input.
# For each number n from 2 to x - 1, test if x is evenly divisible by n.
# If it is, return False.
# If none of them are, then return True.
# def is_prime(x):
# for i in range(2,x):
# if x%i ==0:
# return True
# else:
# return False
# is_prime(100)
##############################################################################
# codecademy python 5.7
# Define a function called reverse that takes a string textand returns that string in reverse.
# For example: reverse("abcd") should return "dcba".
# You may not use reversed or [::-1] to help you with this.
# You may get a string containing special characters (for example, !, @, or #).
# def Read(str):
# return str[::-1]
# print(Read('abc'))
##############################################################################
# codecademy python 5.8
# Define a function called anti_vowel that takes one string, text,
# as input and returns the text with all of the vowels removed.
# For example: anti_vowel("Hey You!") should return "Hy Y!".
# Don't count Y as a vowel. Make sure to remove lowercase and uppercase vowels.
# import re
# def anti_vowel(str):
# print(re.sub('[aeiou]','',str))
# anti_vowel('Hey You!')
##############################################################################
# codecademy python 5.9
# Define a function scrabble_score that takes a string word as input
# and returns the equivalent scrabble score for that word.
# Assume your input is only one word containing no spaces or punctuation.
# As mentioned, no need to worry about score multipliers!
# Your function should work even if the letters you get are uppercase, lowercase, or a mix.
# Assume that you're only given non-empty strings.
# score = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2,
# "f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3,
# "l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1,
# "r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4,
# "x": 8, "z": 10}
# word = str(input()).lower()
# def scrabble_score(word):
# sum = 0
# for item in word:
# sum = score[item]+sum
# print(sum)
# scrabble_score(word)
##############################################################################
# codecademy python 5.10
# Write a function called censor that takes two strings, text and word, as input.
# It should return the text with the word you chose replaced with asterisks. For example:
# censor("this hack is wack hack", "hack")
# should return:
# "this **** is wack ****"
# Assume your input strings won't contain punctuation or upper case letters.
# The number of asterisks you put should correspond to the number of letters in the censored word.
# text = 'this hack is wack hack'
# word = 'hack'
# def censor(text,word):
# num = 0
# for i in word:
# num +=1
# print(text.replace(word,'*'*num))
# censor(text,word)
##############################################################################
# codecademy python 5.11
# Define a function called count that has two arguments called sequence and item.
# Return the number of times the item occurs in the list.
# For example: count([1, 2, 1, 1], 1) should return 3 (because 1 appears 3 times in the list).
# There is a list method in Python that you can use for this, but you should do it the long way for practice.
# Your function should return an integer.
# The item you input may be an integer, string, float, or even another list!
# Be careful not to use list as a variable name in your code—it's a reserved word in Python!
# def count(sequence,item):
# sum = 0
# for i in sequence:
# if i == item:
# sum+=1
# return sum
##############################################################################
# codecademy python 5.12
# Define a function called purify that takes in a list of numbers,
# removes all odd numbers in the list, and returns the result.
# For example, purify([1,2,3]) should return [2].
# Do not directly modify the list you are given as input;
# instead, return a new list with only the even numbers.
# def purify(x):
# li = []
# for i in x:
# if i %2 ==0:
# li.append(i)
# return li
# print(purify([1,2,3,4]))
##############################################################################
# codecademy python 5.13
# Define a function called product that takes a list of integers as input and
# returns the product of all of the elements in the list.
# For example: product([4, 5, 5]) should return 100 (because 4 * 5 * 5 is 100).
# Don't worry about the list being empty.
# Your function should return an integer.
# def product(x):
# mul = 1
# for i in x:
# mul = i*mul
# return mul
# print(product([12,4,3]))
##############################################################################
# codecademy python 5.14
# Write a function remove_duplicates that takes in a list and removes elements of the list that are the same.
# For example: remove_duplicates([1, 1, 2, 2]) should return [1, 2].
# Don't remove every occurrence, since you need to keep a single occurrence of a number.
# The order in which you present your output does not matter.
# So returning [1, 2, 3] is the same as returning [3, 1, 2].
# Do not modify the list you take as input! Instead, return a new list.
# def remove_duplicates(li):
# li1 = []
# for i in li:
# if i not in li1:
# li1.append(i)
# return li1
# print(remove_duplicates([1,1,2,2,3,3,4]))
##############################################################################
# codecademy python 5.15
# Write a function called median that takes a list as an input
# and returns the median value of the list. For example: median([1, 1, 2]) should return 1.
# The list can be of any size and the numbers are not guaranteed to be in any particular order. Make sure to sort it!
# If the list contains an even number of elements, your function should return the average of the middle two.
# def median(li):
# li = sorted(list(li))
# print(li)
# num = 0
# for i in li:
# num +=1
# if (num-1)%2==0:
# return li[int(num/2)]
# else:
# return ((li[int((num/2-0.5)-1)]+li[int((num/2-0.5)+1)]))/2
# print(median([6,2,4,8,9,1,2,3,3,7]))

codecademy练习记录--Learn Python(70%)的更多相关文章

  1. 《Learn python the hard way》Exercise 48: Advanced User Input

    这几天有点时间,想学点Python基础,今天看到了<learn python the hard way>的 Ex48,这篇文章主要记录一些工具的安装,以及scan 函数的实现. 首先与Ex ...

  2. [IT学习]Learn Python the Hard Way (Using Python 3)笨办法学Python3版本

    黑客余弦先生在知道创宇的知道创宇研发技能表v3.1中提到了入门Python的一本好书<Learn Python the Hard Way(英文版链接)>.其中的代码全部是2.7版本. 如果 ...

  3. 笨办法学 Python (Learn Python The Hard Way)

    最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注 ...

  4. 记录:python读取excel文件

    由于最近老是用到python读取excel文件,所以特意记录一下python读取excel文件的大体框架. 库:xlrd(读),直接pip安装即可.想要写excel文件的话,安装xlwd库即可,也是直 ...

  5. 学 Python (Learn Python The Hard Way)

    学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注释和井号 习题 ...

  6. 工作记录之 [ python请求url ] v s [ java请求url ]

    背景: 模拟浏览器访问web,发送https请求url,为了实验需求需要获取ipv4数据包 由于不做后续的内容整理(有内部平台分析),故只要写几行代码请求发送https请求url列表中的url即可 开 ...

  7. 快速入门:十分钟学会PythonTutorial - Learn Python in 10 minutes

    This tutorial is available as a short ebook. The e-book features extra content from follow-up posts ...

  8. Python basic (from learn python the hard the way)

    1. How to run the python file? python ...py 2. UTF-8 is a character encoding, just like ASCII. 3. ro ...

  9. 记录一些python内置函数

    整理一些内置函数,平时用得比较少,但是时不时遇上,记录一下吧(嘻嘻(●'◡'●)) 1.help() 查看模块or函数的帮助文档 help(pandas) #模块 Help on package pa ...

随机推荐

  1. 前端开发—Javascript

    Javascript 语言简介: 语言规范: 注释:/  这是单行注释 /   /* 换行*/ 多行注释 结束符: :分号 语法基础 变量 变量声明 1 变量名可以是 数字 字母 下划线 $ 组成,不 ...

  2. elasticsearch聚合函数

    计算每个tag下的商品数量 GET /ecommerce/product/_search { "aggs": {  //聚合 "group_by_tags": ...

  3. nyoj158-省赛来了

    省赛来了 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 一年一度的河南省程序设计大赛又要来了. 竞赛是要组队的,组队形式:三人为一队,设队长一名,队员两名. 现在问题就 ...

  4. [网络流24题] 最长k可重区间集问题 (费用流)

    洛谷传送门 LOJ传送门 很巧妙的建图啊...刚了$1h$也没想出来,最后看的题解 发现这道题并不类似于我们平时做的网络流题,它是在序列上的,且很难建出来二分图的形. 那就让它在序列上待着吧= = 对 ...

  5. 批量删除.svn目录

    find . -type d -name ".svn"|xargs rm -rf find . -type d -iname ".svn" -exec rm - ...

  6. @Bean 指定初始化和销毁方法

    bean 的生命周期 bean 的创建 --> 初始化 --> 销毁 ioc 容器管理 bean 的声明周期 可以自定义初始化和销毁方法 构造器( 对象创建 )被调用时机 单实例:在容器启 ...

  7. 有关elasticsearch分片策略的总结

    最近在优化部分业务的搜索吞吐率,结合之前优化过写请求的经验,想和大家讨论下我对es分片在不同场景下的分配策略的思路   原先普通索引我的分片策略是: 主分片=节点数,副本=1,这样可以保证业务数据一定 ...

  8. lim的日常生活

     

  9. VC版超级记事本

    这是学习VC时的一个大作业,超级记事本.突然发现了,传上来供大家学习參考! 一.  功能需求: 1. 能在原有像记事本程序的基础上加入很多其它功能: 1).可以改变背景颜色. 2).可以改变字体颜色. ...

  10. 从HTTP 2.0想到的关于传输层协议的一些事

    0.HTTP协议的历史 我也不知道... 1.关于HTTP 2.0 收到了订阅的邮件,头版是说HTTP 2.0的内容,我本人不是非常关注HTTP这一块儿.可是闲得无聊时也会瞟两眼的.HTTP 2.0的 ...