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

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

运行结果:

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.

hello world

hello world!hello again

hello world! hello again

思考题

让你的脚本再多打印一行。

print("hello world"+'\n')

让你的脚本只打印一行。

print("hello world!",end="")

print("hello again")

print("hello world!","hello again")

在一行的起始位置放一个 ‘#’ (octothorpe) 符号。它的作用是什么?自己研究一下。

答:注释作用。

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 a piece of code:

print "This won't run."

print("This will run.")

输出:

I could have code like this.

This will run.

思考题:

没有找到错误。。

3、

打印文字i will now count my chickens:

print("i will now count my chickens:")

输出hens 后面附上25+(30/6)的结果

print("hens",25+30//6)

输出roosters 后面附上100减去(25*3)除以4的余数

print("roosters",100-25*3%4)

打印文字now i will count the eggs:

print("now i will count the eggs:")

打印计算结果(3+2+1-5)+(4%2)-(1//4)+6

print(3+2+1-5+4%2-1//4+6)

打印文字is it true that 3+2<5-7?

print("is it true that 3+2<5-7?")

计算出(3+2)小于(5-7)的布尔值并打印出来

print(3+2<5-7)

打印文字what is 3+2? 后面附上3+2的结果

print("what is 3+2?",3+2)

打印文字what is 5-7?后面附上5-7的结果

print("what is 5-7?",5-7)

打印文字oh,that's why it's false.

print("oh,that's why it's false.")

打印文字how about some more.

print("how about some more.")

打印文字is it greater? 后面附上5大于-2的布尔值结果

print("is it greater?",5>-2)

打印文字is it greater or equal?后面附上5>=-2的布尔值

print("is it greater or equal?",5>=-2)

打印文字is it less or equal?后面附上5<=-2的布尔值

print("is it less or equal?",5<=-2)

输出:

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

思考题:

自己找个想要计算的东西,写一个 .py 文件把它计算出来。计算10的阶乘。

a = 10

b = 1

while a>1:

b = b*a

a = a-1

else:

print(b)

输出:3628800

print("i will now count my chickens:")

print("hens",25.0+30.0//6.0)

print("roosters",100.0-25.0*3.0%4.0)

print("now i will count the eggs:")

print(3.0+2.0+1.0-5.0+4.0%2.0-1.0//4.0+6.0)

print("is it true that 3.0+2.0<5.0-7.0?")

print(3.0+2.0<5.0-7.0)

print("what is 3+2?",3.0+2.0)

print("what is 5-7?",5.0-7.0)

print("oh,that's why it's false.")

print("how about some more.")

print("is it greater?",5.0>-2.0)

print("is it greater or equal?",5.0>=-2.0)

print("is it less or equal?",5.0<=-2.0)

输出:

i will now count my chickens:

hens 30.0

roosters 97.0

now i will count the eggs:

7.0

is it true that 3.0+2.0<5.0-7.0?

False

what is 3+2? 5.0

what is 5-7? -2.0

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

4、

cars = 100

space_in_a_car = 4.0

drivers = 30

passengers = 90

100-30

cars_not_driven = cars-drivers

30

cars_driven = drivers

30*4.0

carpool_capacity = cars_driven*space_in_a_car

90/30

average_passengers_per_car = passengers//cars_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 car pool today.")

print("we need to put about",average_passengers_per_car,"in each car")

输出:

there are 100 cars available

there are only 30 drivers available.

there will be 70 empty cars today.

we can transport 120.0 people today.

we have 90 to car pool today.

we need to put about 3 in each car

思考题:

作者打错了变量,多打了一个

不会有问题,因为人数肯定是整数。

a = 10

b = 11

c = a+b

print(c)

5、

my_name = "zed a. shaw"

my_age = 35 #not a lie

my_height = 74#inches

my_weight = 180 #lbs

my_eyes = 'blue'

my_teeth = 'white'

my_hair = 'brown'

print("let's talk about %s."% my_name)

print("he's %d inches tall."% my_height)

print("he's %d pounds heavy"% my_weight)

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

print("he's got %s eyes and %s hair."% (my_eyes,my_hair))

print("his teeth are usually %s depending on the coffee." % my_teeth)

this line is tricky, try to get it exactly right

print("if i add %d , %d ,and %d i get %d." %(my_age,my_height,my_weight,my_age+my_height+my_weight))

输出:

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 blue eyes and brown hair.

his teeth are usually white depending on the coffee.

if i add 35 , 74 ,and 180 i get 289.

思考题:

name = "zed a. shaw"

age = 35 #not a lie

height = 74#inches

weight = 180 #lbs

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

输出:

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 blue eyes and brown hair.

his teeth are usually white depending on the coffee.

if i add 35 , 74 ,and 180 i get 289.

英镑和英寸转换

6、

06

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

10赋值给了%d的位置。

binary = "binary"

do_not = "don't"

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

多个参数赋值需要在括号里,第一个字符串包含字符串

print(x)

print(y)

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 = "this is the left side of..."

e = "a string with a right side"

print(w+e)

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

思考题:

为什么w+e 可以生成一个更长的字符串、

在原来的后面加上代码

a =w+e

print(a)

输出:

this is the left side of...a string with a right side

7、

print("mary had a little lamb")

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

print("and everywhere that mary 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 waht happens 没有任何反应。。

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

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

结果:

mary had a little lamb

its fleece was white as snow.

and everywhere that mary went.

..........

cheese

burger

思考题:

无任何错误

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

))

最后一行因为其中有段字符串里包含了单引号,所以输出的时候括起来要使用双引号

思考题:

见上面。

9、

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

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.

思考题:

木有

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转义字符串

改成单引号后没有区别。

!!!将转义序列和格式化字符串放到一起,创建一种更复杂的格式。这句话没有明白。答疑时要提出!!!

a = "\t* Catnip\n\t* Grass"

print("ceshi:%r,%s" %(a,a))

输出:

ceshi:'\t* Catnip\n\t* Grass', * Catnip

* Grass

可以看出%s自动把转义的省略了。

python算法1加1_【Python爬虫作业】- 第一周01 笨方法0-10加分题相关推荐

  1. 58同城python_Python实战计划爬虫作业第一周作业:爬58同城

    作业要求: 作业要求1.1 作业要求2 作业要求更改说明:由于58同城页面改版,二手商品的个人卖家均改为了"转转",因此,本次爬虫作业,无法屏蔽转转卖家,而是直接从转转卖家的页面爬 ...

  2. Python爬虫(第一周)

    目录 一.正则表达式 正则表达式的作用 正则表达式的使用 1.match函数 匹配单个字符(规范字符类型) 匹配多个字符(规范字符数量) 匹配开头和结尾 2.search函数 小案例 3.findal ...

  3. Python学习心得第一周-01

    一 编程与编程语言 python是一门编程语言,作为学习python的开始,需要事先搞明白:编程的目的是什么?什么是编程语言?什么是编程? 编程的目的: #计算机的发明,是为了用机器取代/解放人力,而 ...

  4. python项目策划书_Python实战计划学习第一周

    第二节练习项目:爬取商品信息 from bs4 import BeautifulSoup import re # 引入正则表达式 # 本地静态网页路径 path = './index.html' wi ...

  5. 现代软件工程 作业 第一周博客作业

    第一周作业 1. 介绍自己,建博客 我是一名大三的学生,平时爱好看看书,感觉没啥特长. 要说有什么优势技能,就是文笔还可以吧. 从初三开始写日记,基本上上学的日子每天都写,一直到大一结束. 2. 现状 ...

  6. python给视频加水印_爬虫视频统一添加水印(moviepy实现)

    这不昨天刚解决一个问题我们部门老大又来提问题啦,要求给所有视频统一添加水印,心想这不是运营美工干的活嘛,我直接录视频不就行啦!哈哈哈 只能这里唠叨一下,该干还要撸起袖子干起来啊!谁让我们是程序媛呢!直 ...

  7. 将python算法转为scala_将Python转换为scalaasp

    我有一个Python代码,我想把它转换成Scala Spark,我的算法是LDA(潜在Dirichlet Allocation)的扩展,因为这个算法有一个采样过程,当数据非常大时非常耗时,我知道Spa ...

  8. python计算时间加减,python datetime库使用和时间加减计算

    datetime库使用 一.操作当前时间 1.获取当前时间 >>> import datetime >>> print datetime.datetime.now( ...

  9. Python学习(作业第一周)

    日期:2019年2月26日 版本:python 3.7 第一题:Hello World ‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬ ...

最新文章

  1. python有趣的小项目-有趣的python小项目,自动生成有趣的表情包!
  2. 【性能优化】 之 HINTS 相关作业
  3. 何雯娜 (为奥运冠军名字作诗)
  4. 知乎上-翻车的笔记本
  5. opencv-api FlannBasedMatcher
  6. Java 获取项目文件路径
  7. python语法简洁清晰特色之一是强制用什么作为语句缩进_Python解决矩阵问题
  8. java基础篇---网络编程(TCP程序设计)
  9. NLP学习02--卷积神经网络CNN
  10. WinForm中的特殊窗体效果:渐变窗口和信息提示窗口
  11. 九、 Excel二维码制作和插件推荐
  12. 为大家提供了解内网穿透的内容
  13. 升级macos beta_如何选择退出macOS开发人员或公开Beta版
  14. wps2019数据分析加载项_wpsexcel数据分析工具在哪里
  15. MATLAB之心形图绘制
  16. 有哪些办法可以将ip地址更换?
  17. SpringBoot-注解日志 Aop注解切入点
  18. Linux学习-96-win和vmware的linux系统之间文件传递
  19. mysql数据库交叉连接_MySQL交叉连接(CROSS JOIN)
  20. 详细 | 图神经网络从入门到入门

热门文章

  1. C#窗体Click事件没反应
  2. 第六十九章 Caché 函数大全 $WCHAR 函数
  3. 顺序的分数 Ordered Fractions [USACO 2.1]
  4. Floodlight模块分析:forwarding模块
  5. dede判断字段是否为空
  6. Python代码写好了怎么运行?为大家详细讲讲如何运行Python代码
  7. 计算机网络到底讲了些什么
  8. WEB漏洞之:海洋CMS代码执行(CNVD-2020-22721)
  9. Java中的Hash Code到底是什么?
  10. 阿里巴巴年薪800k大数据全栈工程师成长记