##############################################################################
# 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. springboot版本控制

    HandlerMapping通过继承InitializingBean接口在完成实例后,扫描所有的Controller和标识RequestMapping的方法,缓存这个映射对应关系.然后在应用运行的时候 ...

  2. Fiddler4抓包工具使用教程

    本文参考自http://blog.csdn.net/ohmygirl/article/details/17846199,纯属读书笔记,加深记忆 1.抓包工具有很多,为什么要使用Fiddler呢?原因如 ...

  3. python笔记3----第一个小爬虫

    1.先看看要爬的网站有没有爬虫协议,可以看该网站有没有robots.txt,如豆瓣的: 2.requests模块:[requests是第三方,代码比python自带的urllib模块简单] 先加载re ...

  4. Django:Admin,Cookie,Session

    一. Admin的配置 1.Admin基础设置 admin是django强大功能之一,它能够从数据库中读取数据,呈现在页面中,进行管理.默认情况下,它的功能已经非常强大,如果你不需要复杂的功能,它已经 ...

  5. [网络流24题] 方格取数问题/骑士共存问题 (最大流->最大权闭合图)

    洛谷传送门 LOJ传送门 和太空飞行计划问题一样,这依然是一道最大权闭合图问题 “骑士共存问题”是“方格取数问题”的弱化版,本题解不再赘述“骑士共存问题”的做法 分析题目,如果我们能把所有方格的数都给 ...

  6. 1、认识和安装MongoDB

    MongoDB简介:MongoDB是一个基于分布式文件存储的数据库,由C++语言编写.目的是为WEB应用提供扩展的高性能的数据存储解决方案.MongoDB是一个介于关系型数据库和非关系型数据库之间的产 ...

  7. ElasticSearch[v6.2] 在实际项目中的应用

    摘要:本文所讲述的内容,为ElasticSearch(以下简称ES)全文搜索引擎在实际大数据项目的应用:ES的底层是开源库 Lucene.但是,你没法直接用 Lucene,必须自己写代码去调用它的接口 ...

  8. 使用IO,递归打印目录树

    package chengbaoDemo; import java.io.File; import java.io.IOException; public class TestIOFile { pub ...

  9. SQL-Oracle-创建Dblink

    create database link DBLINK_IMARK_RAC connect to imark identified by imarkDB12345 using '(DESCRIPTIO ...

  10. [Design]制作磨砂效果

    比较适合运用到网页或者APP的设计当中,推荐过来和飞特的朋友们一起分享学习了,先来看看最终的效果图吧 具体的制作步骤如下: