习题0

在老师的帮助下完成,特别感谢程程老师!

习题1

#-*- coding: utf-8-*-

print("Hello World!")

print("Hello Again")

print("I like typing this.")

print("This is fun.")

print('Yay! Printing.')

print("I'd much rather you 'not'.")

print('I "said" do not touch this.')

C:\ProgramData\Anaconda3\python.exe E:/pyproject/ex1.py

Hello World!

Hello Again

I like typing this.

This is fun.

Yay! Printing.

I'd much rather you 'not'.

I "said" do not touch this.

Process finished with exit code 0

#在每行前加#用来表示注解,也可指临时禁用此行代码。

习题2

print("I could have code like this.") # and the comment after is ignored

# You can also use a comment to "disable" or comment out a piece of code:

# print("This will run.")

print("This will run.")

print("Hi # there.")

C:\ProgramData\Anaconda3\python.exe E:/pyproject/ex2.py

I could have code like this.

This will run.

Hi # there.

Process finished with exit code 0

习题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)

C:\ProgramData\Anaconda3\python.exe E:/pyproject/ex3.py

I will now count my chickens:

Hens 30

Roosters 97

Now I will count the eggs:

7

Is it true that 3 + 2 < 5 - 7?

False

What is 3 + 2? 5

What is 5 - 7? -2

Oh, that's why it's False.

How about some more.

Is it greater? True

Is it greater or equal? True

Is it less or equal? False

Process finished with exit code 0

# 在Python3中//表示除以,在Python2中/表示除以,且结果为整数,不是浮点数。%指求余数符号。运算优先级为括号,指数,乘,除,加,减。

习题4

cars = 100

space_in_a_car = 4

drivers = 30

passengers = 90

cars_driven = drivers

cars_not_driven = cars - drivers

carpool_capacity = cars_driven * space_in_a_car

average_passengers_per_car = passengers / cars_not_driven

print("There are", cars, "cars available.")

print("There are only", drivers, "drivers available.")

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.")

C:\ProgramData\Anaconda3\python.exe E:/pyproject/ex3.py

I will now count my chickens:

Hens 30

Roosters 97

Now I will count the eggs:

7

Is it true that 3 + 2 < 5 - 7?

False

What is 3 + 2? 5

What is 5 - 7? -2

Oh, that's why it's False.

How about some more.

Is it greater? True

Is it greater or equal? True

Is it less or equal? False

Process finished with exit code 0

# x, y, j为常用变量名,赋值时用“=”,即x = ?

习题5

#name = 'Zed A. Shaw'

#age = 35 # not a lie

#height = 74 # inches

#weight = 180 # 1bs

#eyes = 'Blue'

#teeth = 'White'

#hair = 'Brown'

#print("Let's talk about %s." % name)

#print("He's %d inches tall." % height)

#print("He's %d pounds heavy." % weight)

#print("Actually that's not too heavy.")

#print("He's got %s eyes and %s hair." % (eyes, hair))

#print("His teeth are usually %s depending on the coffee." % teeth)

# this line is tricky, try to get it exactly right

#print("If I add %d, %d, and %d, I get %d." % (age, height, weight, age + height + weight))

from sympy.physics.units import centimeters, kg

name = 'Zed A. Shaw'

age = 35

height = 74 # inches * 2.54 centimeters

weight = 180 # 1bs * 0.4536 kilograms

eyes = 'Blue'

teeth = 'White'

hair = 'Brown'

# how to transform height and weight?

print("Let's talk about %r." % name)

print("He's %r centimeters tall." % height)

print("He's %r kilograms heavy." % weight)

print("Actually that's not too heavy.")

print("He's got %r eyes and %r hair." % (eyes, hair))

print("His teeth are usually %r depending on coffee." % teeth)

# this line is tricky, try to get it exactly right

print("If I add %r, %r, and %r I get %r." % (age, height, weight, age + height + weight))

C:\ProgramData\Anaconda3\python.exe E:/pyproject/ex5.py

Let's talk about 'Zed A. Shaw'.

He's 74 centimeters tall.

He's 180 kilograms heavy.

Actually that's not too heavy.

He's got 'Blue' eyes and 'Brown' hair.

His teeth are usually 'White' depending on coffee.

If I add 35, 74, and 180 I get 289.

Process finished with exit code 0

学习总结:想通过Python直接进行公式换算没有解决。%s用来表示代入后面的字符串,%d表示取整数,%r可以代入任何内容既可为字符串又可为数字。

# Python的所有格式符

%s 字符串 (采用str()的显示)

%r 字符串 (采用repr()的显示)

%c 单个字符

%b 二进制整数

%d 十进制整数

%i 十进制整数

%o 八进制整数

%x 十六进制整数

%e 指数 (基底写为e)

%E 指数 (基底写为E)

%f 浮点数

%F 浮点数,与上相同

%g 指数(e)或浮点数 (根据显示长度)

%G 指数(E)或浮点数 (根据显示长度)

%% 字符"%"

习题6

x = "There are %d types of people." % 10

binary = "binary"

do_not = "don't"

y = " Those who know %s and those who %s." % (binary, do_not)

#打印变量x和变量y

print(x)

print(y)

#其中,%r 指不管什么都打印出来,此处用变量x字符串代替,以下同理。

print("I said: %r." % x)

print("I also said: '%s." % y)

hilarious = False

joke_evaluation = "Isn't that joke so funny?! %r"

print(joke_evaluation % hilarious)

#打印变量w和变量e,且两变量赋值都为字符串

w = "This is the left side of ..."

e = "a string with a right side."

print(w + e)

C:\ProgramData\Anaconda3\python.exe E:/pyproject/ex6.py

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.

Process finished with exit code 0

习题7

# 打印字符串

print("Mary had a little lamb.")

# 打印字符串,其中%s用字符串snow 替代

print("Its fleece was white as %s." % 'snow')

# 打印

print("And everywhere that Mary went.")

# 打印 10次 "."

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必须顶格

print(end1 + end2 + end3 + end4 + end5 + end6)

print(end7 + end8 + end9 + end10 + end11 + end12)

C:\ProgramData\Anaconda3\python.exe E:/pyproject/ex7.py

Mary had a little lamb.

Its fleece was white as snow.

And everywhere that Mary went.

..........

Cheese

Burger

Process finished with exit code 0

#学习总结当命令行中出现*,用来表示重复出现,后面数字为几,则重复*前面的内容多少次。

习题8

formatter = "%r %r %r %r"

print(formatter % (1, 2, 3, 4))

print(formatter % ("one", "two", "three", "four"))

print(formatter % (True, False, False, True))

print(formatter % (formatter, formatter, formatter, formatter))

print(formatter % ("I had this thing.",

"That you could type up right.",

"But it didn't sing.",

"So I said goodnight."))

C:\ProgramData\Anaconda3\python.exe E:/pyproject/ex8.py

1 2 3 4

'one' 'two' 'three' 'four'

True False False True

'%r %r %r %r' '%r %r %r %r' '%r %r %r %r' '%r %r %r %r'

'I had this thing.' 'That you could type up right.' "But it didn't sing." 'So I said goodnight.'

Process finished with exit code 0

#学习总结:%s与%r是有区别的,通常%s仅用于表示代入字符串,而%r多用于指debug中的原始数据,之任何内容都可以代入命令行,任何内容都可以打印出来。r%用于debug,s%用于显示。

习题9

# Here's some new strange stuff, remember type ot 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.

""")

C:\ProgramData\Anaconda3\python.exe E:/pyproject/ex9.py

Here are the days: Mon Tue Wed Thu Fri Sat Sun

Here are the months: Jan

Feb

Mar

Apr

May

Jun

Jul

Aug

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.

Process finished with exit code 0

#学习总结: 字符串以\n开始表示换行。为了将字符串连接起来,可用+连接。

习题10

#print("I am 6'2\" tall.")

#print('I am 6\'2" tall.')

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

"""

C:\ProgramData\Anaconda3\python.exe E:/pyproject/ex10.py

I'm tabbed in.

I'm split

on a line.

I'm \ a\ cat.

I'll do a list:

* Cat food

* Fishies

* Catnip

* Grass

Process finished with exit code 0

#学习总结:\或\\代表转义,是将难以打印的特殊字符放在字符串,使其具有特别的意义。在打印多行命令行时用"""三引号,并且中间不可以有空格。当使用'''三单引号和使用"""三双引号打印没有区别。

python爬虫作业帮_【Python爬虫】01作业相关推荐

  1. html网页设计代码作业——家乡介绍-长治(8页) HTML+CSS+JavaScript 学生DW网页设计作业成品 html网页制作期末大作业成品_网页设计期末作业

    HTML5期末大作业:家乡介绍网站设计--家乡介绍-长治(8页) HTML+CSS+JavaScript 学生DW网页设计作业成品 html网页制作期末大作业成品_网页设计期末作业 常见网页设计作业题 ...

  2. html期末作业代码网页设计——云南民族文化(8页) HTML+CSS+JavaScript html网页制作期末大作业成品_网页设计期末作业

    HTML5期末大作业:家乡文化网站设计--云南民族文化(8页) HTML+CSS+JavaScript html网页制作期末大作业成品_网页设计期末作业 常见网页设计作业题材有 个人. 美食. 公司. ...

  3. HTML5期末大作业:XXX 网站设计——电影请以你的名字呼唤我(4页)HTML+CSS+JavaScript html网页制作期末大作业成品_网页设计期末作业

    HTML5期末大作业:XXX 网站设计--电影请以你的名字呼唤我(4页)HTML+CSS+JavaScript html网页制作期末大作业成品_网页设计期末作业 常见网页设计作业题材有 个人. 美食. ...

  4. 作业帮家长版的计算机怎么打开,作业帮家长版安装方法 作业帮家长版app特色...

    作业帮怎么安装?作业帮家长版是一款帮助想辅导自己孩子功课但缺无从下手的家长们设计的app.下面小编就为玩家带来作业帮家长版安装方法,一起来看看吧. 作业帮家长版安装方法 作业帮家长版是一款帮助想辅导自 ...

  5. HTML5期末大作业:水果商城网站设计——蔬菜水果商城(10页) HTML+CSS+JavaScript 学html网页制作期末大作业成品_网页设计期末作业

    HTML5期末大作业:水果商城网站设计--蔬菜水果商城(10页) HTML+CSS+JavaScript 学html网页制作期末大作业成品_网页设计期末作业 常见网页设计作业题材有 个人. 美食. 公 ...

  6. python简单爬虫程序分析_[Python专题学习]-python开发简单爬虫

    掌握开发轻量级爬虫,这里的案例是不需要登录的静态网页抓取.涉及爬虫简介.简单爬虫架构.URL管理器.网页下载器(urllib2).网页解析器(BeautifulSoup) 一.爬虫简介以及爬虫的技术价 ...

  7. python 爬虫是什么_“python爬虫“是什么呢?

    Python爬虫是用Python编程语言实现的网络爬虫,主要用于网络数据的抓取和处理,相比于其他语言,Python是一门非常适合开发网络爬虫的编程语言,大量内置包,可以轻松实现网络爬虫功能. Pyth ...

  8. 基于python的网络爬虫开题报告_网络爬虫开题报告.docx

    网络爬虫开题报告 网络爬虫开题报告 篇一:毕设开题报告 及开题报告分析 开题报告如何写 注意点 1.一.对指导教师下达的课题任务的学习与理解 这部分主要是阐述做本课题的重要意义 2.二.阅读文献资料进 ...

  9. python爬虫ip限制_简单爬虫,突破IP访问限制和复杂验证码,小总结

    简单爬虫,突破复杂验证码和IP访问限制 好吧,看题目就知道我是要写一个爬虫,这个爬虫的目标网站有一些反爬取意识,所以就有了本文了. 我先说说场景吧: 由于工作需要,平时有一大堆数据需要在网上查询,并归 ...

  10. python朋友圈刷屏_“Python太火了!请救救Java!”9万程序员刷屏朋友圈 !

    没想到有生之年,笔者能观察到"霸主陨落"的过程,继PLPY4月榜单官宣,Python躺赢,再度"夺"冠,实力甩下Java和C后,近期,Stack Overflo ...

最新文章

  1. 浅谈企业MES与ERP系统集成
  2. Python模块: 文件和目录os+shutil
  3. leetcode 90. 子集 II(回溯算法)
  4. 尼尔机器人技能快捷键_《尼尔机械纪元》连招操作技巧
  5. Android内容提供器的应用,基于Android的智能终端应用防护系统短信过滤子模块的设计与实现...
  6. python中出现iterator should return strings, not bytes怎么解决
  7. 堆——神奇的优先队列(上)
  8. useCallback()和useMemo()的作用
  9. spring思想分析
  10. paintevent参数_Qt学习: QPaintEvent和QMouseEvent的简单程序示例
  11. ffplay播放flv文件没有声音的解决方法
  12. 快速实现APP混合开发(Hybrid App开发)攻略
  13. python lime_本地可解释模型不可知的解释– LIME in Python
  14. Python环境与PyCharm编辑器的安装教程
  15. STM32H7 DAC2+BDMA
  16. 爆火的ChatGPT到底能做什么?5分钟带你进入AI的大门
  17. 【图解版】HashMap原理初探
  18. 服务器时装不显示不出来,常见问题FAQ汇总
  19. IDEA创建JavaWeb项目配置
  20. EcmaScript 6 - 块级作用域(block scope)

热门文章

  1. PyCharm安装步骤
  2. Emacs之快捷键大全
  3. Android Native Hook工具
  4. Android项目持续集成之Jenkins的使用
  5. 一张图看尽 Linux 内核运行原理
  6. UE4之判断点是否在矩形内
  7. 基于python人脸识别考勤系统(语音播报)
  8. 记录一次被DDOS攻击,攻击类型:UDPFLOOD
  9. ubuntu18.04安装mysql8.0中遇到的问题及解决方法
  10. 3h精通OpenCV(一)- 读取图像视频与网络摄像头