python搜題,python爬蟲作業幫_【Python爬蟲】01作業

 2023-12-06 阅读 33 评论 0

摘要:習題0在老師的幫助下完成,特別感謝程程老師!習題1#-*- coding: utf-8-*-print("Hello World!")python搜題,print("Hello Again")print("I like typing this.")print("This is fun.")print('Yay! Printing.')print(

習題0

在老師的幫助下完成,特別感謝程程老師!

習題1

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

print("Hello World!")

python搜題,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.

python123課后作業、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

python程序設計課后答案?# 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.

python作業,This will run.

Hi # there.

Process finished with exit code 0

習題3

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

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

python爬蟲接單網。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)

python大作業,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)

python爬蟲教程。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

python程序設計基礎課后答案。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.

python 類,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

python爬蟲大作業報告?cars = 100

space_in_a_car = 4

drivers = 30

passengers = 90

cars_driven = drivers

cars_not_driven = cars - drivers

python爬蟲題庫。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.")

python題庫網站,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

#學習總結:\或\\代表轉義,是將難以打印的特殊字符放在字符串,使其具有特別的意義。在打印多行命令行時用"""三引號,并且中間不可以有空格。當使用'''三單引號和使用"""三雙引號打印沒有區別。

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/1/188581.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息