导航:首页 > 编程语言 > pjpython

pjpython

发布时间:2022-04-25 18:27:24

1. 写一个20行以上的python简单代码

classPrice:
ticket_d=100
ticket_w=ticket_d*1.2
defrq(self):
self.a=int(input('请输入是平日还是周末(平日:1/周末:0):'))
ifself.a==0:
self.p=self.ticket_w
ifself.a==1:
self.p=self.ticket_d
defpj(self):
input('请输入是人数'+' ')
self.ad=int(input('大人数量:'))
self.ch=int(input('儿童数量:'))
self.money=self.p*self.ad+self.p*self.ch/2
print('%f'%self.money)

classTicket():
def__init__(self,weekend=False,child=False):
self.exp=100
ifweekend:
self.inc=1.2
else:
self.inc=1
ifchild:
self.discount=0.5
else:
self.discount=1
defcalcPrice(self,num):
returnself.exp*self.inc*self.discount*num

alt=Ticket()
child=Ticket(child=True)
print("2个成人+1个小孩平日票价为:%.2f"%(alt.calcPrice(2)+child.calcPrice(1)))

2. 如何用python统计单词的频率

代码:

passage="""Editor’s Note: Looking through VOA's listener mail, we came across a letter that asked a simple question. "What do Americans think about China?" We all care about the perceptions of others. It helps us better understand who we are. VOA Reporter Michael Lipin begins a series providing some answers to our listener's question. His assignment: present a clearer picture of what Americans think about their chief world rival, and what drives those perceptions.

Two common American attitudes toward China can be identified from the latest U.S. public opinion surveys published by Gallup and Pew Research Center in the past year.

First, most of the Americans surveyed have unfavorable opinions of China as a whole, but do not view the country as a threat toward the United States at the present time.

Second, most survey respondents expect China to pose an economic and military threat to the United States in the future, with more Americans worried about the perceived economic threat than the military one.

Most Americans view China unfavorably

To understand why most Americans appear to have negative feelings about China, analysts interviewed by VOA say a variety of factors should be considered. Primary among them is a lack of familiarity.

"Most Americans do not have a strong interest in foreign affairs, Chinese or otherwise," says Robert Daly, director of the Kissinger Institute on China and the United States at the Washington-based Wilson Center.

Many of those Americans also have never traveled to China, in part because of the distance and expense. "That means that like most human beings, they take short cuts to understanding China," Daly says.

Rather than make the effort to regularly consume a wide range of U.S. media reports about China, analysts say many Americans base their views on widely-publicized major events in China's recent history."""

passage=passage.replace(","," ").replace("."," ").replace(":"," ").replace("’","'").

replace('"'," ").replace("?"," ").replace("!"," ").replace(" "," ")#把标点改成空格

passagelist=passage.split(" ")#拆分成一个个单词

pc=passagelist.()#复制一份

for i in range(len(pc)):

pi=pc[i]#这一个字符串

if pi.count(" ")==len(pi):#如果全是空格

passagelist.remove(pi)#删除此项

worddict={}

for j in range(len(passagelist)):

pj=passagelist[j]#这一个单词

if pj not in worddict:#如果未被统计到

worddict[pj]=1#增加单词统计,次数设为1

else:#如果统计过了

worddict[pj]+=1#次数增加1

output=""#按照字母表顺序,制表符

worddictlist=list(worddict.keys())#提取所有的单词

worddictlist.sort()#排序(但大小写会出现问题)

worddict2={}

for k in worddictlist:

worddict2[k]=worddict[k]#排序好的字典

print("单次 次数")

for m in worddict2:#遍历输出

tabs=(23-len(m))//8#根据单次长度输入,如果复制到表格,请把此行改为tabs=2

print("%s%s%d"%(m," "*tabs,worddict[m]))

注:加粗部分是您要统计的短文,请修改。我这里的输出效果是:

American 1

Americans 9

Center 2

China 10

China's 1

Chinese 1

Daly 2

Editor's 1

First 1

Gallup 1

His 1

Institute 1

It 1

Kissinger 1

Lipin 1

Looking 1

Many 1

Michael 1

Most 2

Note 1

Pew 1

Primary 1

Rather 1

Reporter 1

Research 1

Robert 1

S 2

Second 1

States 3

That 1

To 1

Two 1

U 2

United 3

VOA 2

VOA's 1

Washington-based1

We 1

What 1

Wilson 1

a 10

about 6

across 1

affairs 1

all 1

also 1

among 1

an 1

analysts 2

and 5

answers 1

appear 1

are 1

as 2

asked 1

assignment 1

at 2

attitudes 1

base 1

be 2

because 1

begins 1

beings 1

better 1

but 1

by 2

came 1

can 1

care 1

chief 1

clearer 1

common 1

considered 1

consume 1

country 1

cuts 1

director 1

distance 1

do 3

drives 1

economic 2

effort 1

events 1

expect 1

expense 1

factors 1

familiarity 1

feelings 1

foreign 1

from 1

future 1

have 4

helps 1

history 1

human 1

identified 1

in 5

interest 1

interviewed 1

is 1

lack 1

latest 1

letter 1

like 1

listener 1

listener's 1

mail 1

major 1

make 1

many 1

means 1

media 1

military 2

more 1

most 4

negative 1

never 1

not 2

of 10

on 2

one 1

opinion 1

opinions 1

or 1

others 1

otherwise 1

our 1

part 1

past 1

perceived 1

perceptions 2

picture 1

pose 1

present 2

providing 1

public 1

published 1

question 2

range 1

recent 1

regularly 1

reports 1

respondents 1

rival 1

say 2

says 2

series 1

short 1

should 1

simple 1

some 1

strong 1

survey 1

surveyed 1

surveys 1

take 1

than 2

that 2

the 16

their 2

them 1

they 1

think 2

those 2

threat 3

through 1

time 1

to 7

toward 2

traveled 1

understand 2

understanding 1

unfavorable 1

unfavorably 1

us 1

variety 1

view 2

views 1

we 2

what 2

who 1

whole 1

why 1

wide 1

widely-publicized1

with 1

world 1

worried 1

year 1

(应该是对齐的,到这就乱了)

注:目前难以解决的漏洞

1、大小写问题,无法分辨哪些必须大写哪些只是首字母大写

2、's问题,目前如果含有只能算为一个单词里的

3、排序问题,很难做到按照出现次数排序

3. 如何用python分别提取出某个像素的rgb值并写入一个一行三列的数组中。

可以使用 Python Image Library 做,load() 函数会返回一个对象,这个对象我们可以把它当作一个二维数组对待,而数组中存放的就是点的 RGB 值,可以很容易地访问到任何像素点的 RGB 值:

fromPILimportImage

#可以支持很多种图片格式.
im=Image.open("your_picture.jpg")
pix=im.load()

#获得图片的尺度,可以用于迭代
printim.size

#获得某个像素点的RGB值,像素点坐标由[x,y]指定
printpix[x,y]

#设置[x,y]点的RGB的值为value
pix[x,y]=value

4. python两个列表比较

直接遍历即刻
for i in a:
if i in b:
c.append (i)

5. 如何入门 Python 爬虫

http://wenku..com/link?url=hTf6rVqe3--z_,详细信息可以参考这个,希望可以帮到你

6. Python作业题,要求定义一个函数输入ABCDE一串字母,每个字母代表一个分数,计算平均分。

出现那个错误,是因为自定义函数zh没有返回值,所以导致a=zh(cj[i]);a没有类型(NoneType)

我帮你把Python程序改完了,你看看吧(注意程序的缩进,因为python程序依赖缩进判断程序逻辑)

#!/usr/bin/python
#conding=utf-8
importstring
defzh(m):
iford(m)==ord("A"):
return95
iford(m)==ord("B"):
return85
iford(m)==ord("C"):
return75
iford(m)==ord("D"):
return65
iford(m)==ord("E"):
return40
cj=str(input("请输入五门成绩:"))
zcj=0;
foriinrange(0,5):
a=zh(cj[i]);
zcj=zcj+a;
pjcj=zcj*1.0/5;
print("平均成绩为:{}".format(pjcj))

7. 如何在 Python 中模拟 post 表单来上传文件

在机器上安装了Python的setuptools工具,可以通过下面的命令来安装 poster:

1

<a href="https://www..com/s?wd=easy_install&tn=44039180_cpr&fenlei=-4Bmy-bIi4WUvYETgN-" target="_blank" class="-highlight">easy_install</a> poster

装完之后,安装下面代码就可以实现post表单上传文件了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib2

# 在 urllib2 上注册 http 流处理句柄
register_openers()

# 开始对文件 "DSC0001.jpg" 的 multiart/form-data 编码
# "image1" 是参数的名字,一般通过 HTML 中的 <input> 标签的 name 参数设置

# headers 包含必须的 Content-Type 和 Content-Length
# datagen 是一个生成器对象,返回编码过后的参数
datagen, headers = multipart_encode({"image1": open("DSC0001.jpg", "rb")})

# 创建请求对象(localhost服务器IP地址,5000<a href="https://www..com/s?wd=%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%AB%AF%E5%8F%A3&tn=44039180_cpr&fenlei=-4Bmy-bIi4WUvYETgN-" target="_blank" class="-highlight">服务器端口</a>)
request = urllib2.Request("http://localhost:5000/upload_image", datagen, headers)
# 实际执行请求并取得返回
print urllib2.urlopen(request).read()

8. 什么是文件后缀

文件的后缀名,即文件的扩展名,是操作系统用来标志文件类型的一种机制,是一个类型的元数据。

举例:“小说.txt”的文件名中,小说是主文件名,txt为扩展名(文本、外语全称:Text),表示这个文件是一个纯文本文件。

一个文件可以有或没有扩展名。对于打开文件操作,没有扩展名的文件需要选择程序去打开它,有扩展名的文件会自动用设置好的程序去尝试打开,文件扩展名是一个常规文件的构成部分,但一个文件并不一定需要一个扩展名。

(8)pjpython扩展阅读

常用的文件扩展名

1、doc/docx

表示:Word文档,用微软的word等软件打开。

2、wps

表示:Wps文字编辑系统文档,用金山公司的wps软件打开。

3、xls/xlsx

表示:Excel电子表格,用微软的excel软件打开。

4、ppt/pptx

表示:Powerpoint演示文稿,用微软的powerpoint等软件打开。

5、rar

表示:WinRAR压缩文件,用WinRAR等打开 。

6、pdf

表示:可移植文档格式,用用pdf阅读器打开(比如Acrobat)、用pdf编辑器编辑

7、dwg

表示:CAD图形文件,用AutoCAD等软件打开。

8、exe

表示:可执行文件、可执行应用程序,是Windows视窗操作系统。

阅读全文

与pjpython相关的资料

热点内容
腾讯云拼团云服务器 浏览:364
海南离岛将加贴溯源码销售吗 浏览:244
linux分区读取 浏览:794
单片机液晶显示屏出现雪花 浏览:890
解压器用哪个好一点 浏览:771
什么app看小说全免费 浏览:503
sha和ras加密 浏览:823
韩顺平php视频笔记 浏览:636
阿里云ecs服务器如何设置自动重启 浏览:596
三星电视怎么卸掉app 浏览:317
如何将pdf转换成docx文件 浏览:32
dos命令批量改名 浏览:376
centosphp环境包 浏览:602
mfipdf 浏览:534
电脑解压后电脑蓝屏 浏览:295
外网访问内网服务器如何在路由器设置 浏览:856
2014统计年鉴pdf 浏览:434
linuxoracle用户密码 浏览:757
股票交易pdf 浏览:898
p2papp源码 浏览:308