python程序设计基础答案第七章_Python语言程序设计基础(第2版) 课后题 第七章...

该博客介绍了Python编程基础的第七章内容,包括读取文件、关键字判断、图像压缩和CSV数据转JSON。通过示例代码展示了如何处理字符串停用词,检查是否为Python关键字,实现图像按比例压缩,并将CSV数据转换成格式化的JSON文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考原版答案

import keyword

#7.1

stopwords = '\t\n\r: ()'

functionwords = '.('

word = []

output = ''

lastAvailable = ['from', 'import']

last = False

def readFile(path):

file = open(path,'r',encoding = 'utf-8')

string = file.read()

return string[1:]

def parse(string):

global last

global word

global output

for i in string:

if i in stopwords:

wd = ''.join(word)

res = isKeyWord(wd)

if res == False:

if i not in functionwords and last == False:

wd = wd.upper()

if wd in lastAvailable:

last = True

else:

last = False

output += wd

output += i

word =

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值