写在前面

三十而立之年,开始自学数据分析,工作比较清闲,现发帖记录自己的数据分析之路,数据分析要学很多的东西,经过多月的摸索,目前分两个方面开始学习:

·知识方面:数学为王,拿起书本,重学《概率与统计》、《微积分》、《线性代数》

·软件方面:MySQL、Python

将暂时更新这几个序列,以便记录。

此篇为《笨办法学Python》,全书共52个习题,纯手工码字,视内容多少,分批次发布。

习题0——准备工作

主要是讲解在不同操作系统下安装好Python:

1、下载python:http://www.python.org/downloads,官网下载适合你版本的python,在此不多赘述

2、下载Atom:http://atom.io,找到并安装Atom

3、建议不论是Windows、MAC、还是Linux,都安装原始的Python练习,尽管以后我们会使用Anaconda,Pycharm,但是练好基础还是很有必要的

安装好后的界面

习题1——第一个程序

源代码:

print("Hello World!")
print("Hello Again")
print("I like typing this.")
print("This is fun.")
print('Yay! Printing.')
print("I'd much rather you 'no'.")
print('I "said" do not touch this.')

输出结果:

习题2——注释和#号

源代码:

# A comment, this is so you can read your program later.
# Anything after the # is ignored by python.print("I could have code like this.") # and the comment after is ignored# You can also use a comment to "disable" or comment out code:
# print("This won't run.")print("This will run.")

运行结果:

习题3——数字和数学计算

源代码:

print("I will now count my chickens:")print("Hens", 25 + 30 / 6)
print("Roosters", 100 - 25 * 3 % 4)print("Now I will count the eggs:")print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)print("Is it true that 3 + 2 < 5 - 7?")print(3 + 2 < 5 - 7)print("What is 3 + 2?",3 + 2)
print("What is 5 - 7?",5 - 7)print("Oh, that's why it's False.")print("How about some more.")print("Is it greater?", 5 > -2)
print("Is it greater or equal?", 5 >= -2)
print("Is it less or equal?",5 <= -2)

运行结果:

习题4——变量和命名

源代码:

cars = 100
space_in_a_car = 4.0
drivers = 30
passengers = 90
cars_not_driven = cars - drivers
cars_driven = drivers
carpool_capacity = cars_driven * space_in_a_car
average_passengers_per_car = passengers / cars_drivenprint("There are", cars, "cars availale.")
print("There are only", drivers, "drivers availale.")
print("There will be", cars_not_driven, "empty cars today.")
print("We can transport", carpool_capacity, "people today.")
print("We have", passengers, "to carpool today.")
print("We need to put about", average_passengers_per_car, "in each car.")

运行结果:

习题5——更多的变量和打印

源代码:

my_name = 'Zed A. Shaw'
my_age = 35 # not a lie
my_height = 74 # inches
my_weight = 180 # lbs
my_eyes = 'Black'
my_teeth = 'White'
my_hair = 'Black'print(f"Let's talk about {my_name}.")
print(f"He's {my_height} inches tall.")
print(f"He's {my_weight} pounds heavy.")
print("Actually that's not too heavy.")
print(f"He's got {my_eyes} eyes and {my_hair} hair.")
print(f"His teeth are usually {my_teeth} depending on the coffee.")# this line is tricky, try to get it exactly right
total = my_age + my_height + my_weight
print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}.")

运行结果:

Let's talk about Zed A. Shaw.
He's 74 inches tall.
He's 180 pounds heavy.
Actually that's not too heavy.
He's got Black eyes and Black hair.
His teeth are usually White depending on the coffee.
If I add 35, 74, and 180 I get 289.

习题6——字符串和文本

源代码:

types_of_people = 10
x = f"There are {types_of_people} types of people."binary = "binary"
do_not = "don't"
y = f"Those who know {binary} and those who {do_not}."print(x)
print(y)print(f"I said: {x}")
print(f"I also said: '{y}'")hilarious = False
joke_evaluation = "Isn't that joke so funny?! {}"print(joke_evaluation.format(hilarious))w = "This is the left side of..."
e = "a string with a right side."print(w + e)

运行结果:

There are 10 types of people.
Those who know binary and those who don't.
I said: There are 10 types of people.
I also said: 'Those who know binary and those who don't.'
Isn't that joke so funny?! False
This is the left side of...a string with a right side.

习题7——更多打印

源代码:

print("Marry had a little lamb.")
print("Its fleece was white as {}.".format('snow'))
print("And everywhere that Marry went.")
print("." * 10) # what'd that do?end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
end6 = "e"
end7 = "B"
end8 = "u"
end9 = "r"
end10 = "g"
end11 = "e"
end12 = "r"# watch that comma at the end. try removing it to see what happens
print(end1 + end2 + end3 + end4 + end5 + end6, end = ' ')
print(end7 + end8 + end9 + end10 + end11 + end12)

运行结果:

Marry had a little lamb.
Its fleece was white as snow.
And everywhere that Marry went.
..........
Cheese Burger

习题8——打印,打印

源代码:

formatter = "{} {} {} {}"print(formatter.format(1,2,3,4))
print(formatter.format("one","two","three","four"))
print(formatter.format(True, False, False, True))
print(formatter.format(formatter,formatter,formatter,formatter))
print(formatter.format("Try your","Own text here","Maybe a poem","Or a song about fear"
))

运行结果:

1 2 3 4
one two three four
True False False True
{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}
Try your Own text here Maybe a poem Or a song about fear

习题9——打印,打印,打印

源代码:

# Here's some new strange stuff, remember type it exactly.days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"print("Here are the days: ", days)
print("Here are the months: ",months)print("""
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
""")

运行结果:

Here are the days:  Mon Tue Wed Thu Fri Sat Sun
Here are the months:  Jan
Feb
Mar
Apr
May
Jun
Jul
AugThere's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.

习题10——那是什么

源代码:

tabby_cat = "\tI'm tabbed in."
persian_cat = "I'm split\non a line."
backslash_cat = "I'm \\a \\ cat."fat_cat = """
I'll do a list:
\t* Cat food
\t* Fishies
\t* Catnip\n\t* Grass
"""print(tabby_cat)
print(persian_cat)
print(backslash_cat)
print(fat_cat)

运行结果:

   I'm tabbed in.
I'm split
on a line.
I'm \a \ cat.I'll do a list:* Cat food* Fishies* Catnip* Grass

从零开始学数据分析之——《笨办法学Python》(习题0-10)相关推荐

  1. 小甲鱼python课后题简书_【Python爬虫】-笨办法学 Python 习题01-10

    一.作业内容: 01.将下面的内容写到一个文件中,取名为ex1.py.这个命名方式很重要,Python文件最好以.py结尾. 1 print "Hello World!" 2 pr ...

  2. python考试代码复制_笨办法学Python 习题 26: 恭喜你,现在可以考试了! 错误代码下载链接...

    你已经差不多完成这本书的前半部分了,不过后半部分才是更有趣的.你将学到逻辑,并通过条件判断实现有用的功能. 在你继续学习之前,你有一道试题要做.这道试题很难,因为它需要你修正别人写的代码.当你成为程序 ...

  3. python编程试题定位列表元素的函数是_笨办法学Python 习题 34: 访问列表的元素

    列表的用处很大,但只有你能访问里边的内容时它才能发挥出作用来.你已经学会了按顺序读出列表的内容,但如果你要得到第 5 个元素该怎么办呢?你需要知道如何访问列表中的元素.访问第一个元素的方法是这样的:a ...

  4. python函数作为参数例题_笨办法学Python 习题 19: 函数和变量

    函数这个概念也许承载了太多的信息量,不过别担心.只要坚持做这些练习,对照上个练习中的检查点检查一遍这次的联系,你最终会明白这些内容的. 有一个你可能没有注意到的细节,我们现在强调一下:函数里边的变量和 ...

  5. 《笨办法学python》6_笨办法学Python 习题 25: 更多更多的练习

    我们将做一些关于函数和变量的练习,以确认你真正掌握了这些知识.这节练习对你来说可以说是一本道:写程序,逐行研究,弄懂它. 不过这节练习还是有些不同,你不需要运行它,取而代之,你需要将它导入到 pyth ...

  6. 笨办法学 Python · 续 练习 10:`sort`

    练习 10:sort 原文:Exercise 10: sort 译者:飞龙 协议:CC BY-NC-SA 4.0 自豪地采用谷歌翻译 你正在慢慢地构建我所说的个人流程实践(3P),这根本不是一个新的想 ...

  7. python取模10^9+7_【Python爬虫】笨办法学python 习题1-10

    习题 1 print("Hello World!") print("Hello Again") print("I like typing this.& ...

  8. python从属关系编号_笨办法学Python 习题 42: 对象、类、以及从属关系

    有一个重要的概念你需要弄明白,那就是"类 (class)" 和"对象 (object)" 的区别.问题在于, class 和object 并没有真正的不同.它们 ...

  9. 笨办法学python习题1-10

    #第一个程序 # -*- coding: utf-8 -*- print('Hello World!') print("Hello Again") print("I li ...

  10. 笨办法学python 习题46-windows

    Linux : touch NAME/__init__.py Windows:new-item -type file NAME/__init__.py (终于搞定,记录一下安装过程好了) 本文指在wi ...

最新文章

  1. 通关制单机器人_2020关务节|“数字供应链与智能通关”论坛——如何打造云上跨境贸易生态圈...
  2. 每天一个linux命令(21):find命令之xargs
  3. java爬虫-简单爬取网页图片
  4. discord linux_如何在Discord中应用文本格式
  5. android include 点击事件,Android编程之include文件的使用方法
  6. 2019值得学习的5种编程语言,程序员来告诉你
  7. 数据库(三),底层算法
  8. thinkpad e420 装完新系统后,耳机有声音,外音没有,解决方法
  9. Hessian Spring相关使用的简单例子
  10. 程序员的需要掌握的数学知识
  11. 张一鸣宣布卸任字节跳动CEO,去学习承担社会责任
  12. matlab正弦函数傅里叶变换,正弦函数及其傅里叶变换(一)
  13. 在Linux上安装centos 7镜像详细步骤
  14. U盘提示格式化,8G的U盘变成了8M,并无法格式化打不开U盘解决方法
  15. 邮件营销EDM(Email Direct Marketing) 运营笔记
  16. dlang语法的简单整理
  17. C#实现Winform间的数据交互的三种方法
  18. 阿里本地生活再出发:口碑入高德,备战美团、抖音
  19. 三个人比饭量大小,每个人说了两句话。 A说:B比我吃得多,C和我吃得一样多。 B说:A比我吃得多,A也比C吃得多。 C说:我比B吃得多,B比A吃得多。 事实上饭量越小的人讲对的话越多。
  20. CCF CSP 201803-4 棋局评估

热门文章

  1. 笔记本电脑f11功能键_笔记本电脑F1~F10键原来还有这些功能,以前都不知道!
  2. 目前为止学习过的循环解析过程
  3. 一场技术人的年终盛典:9个老兵对2016年总结与思考
  4. Qt中使用DirectX
  5. 有哪些计算机软件可以录制声音,屏幕录制怎么录声音?这三个录屏软件需了解...
  6. dockerError processing tar file(exit status 1): no space left on device
  7. 介质服务器作用,爱数之介质服务器及介质同步技术
  8. 数据挖掘总结之消极学习与积极学习
  9. 现代检测技术课程实验编程:最小二乘法应用编程
  10. GEE用户贡献的数据列表