小编Klo*_*ano的帖子

Python - AttributeError: '_io.TextIOWrapper' 对象没有属性 'append'

我收到一个错误

ClassFile.append(filelines) AttributeError: '_io.TextIOWrapper' object has no attribute 'append'

在尝试写入文件时。这是关于写一个关于学生分数的文件,他们的名字,姓氏,班级名(只需输入班级Class 1)一个分数和他们的分数的分数。只有他们的最后 3 个分数才会保存在文件中。我不明白这是什么意思。

这是代码

score=3
counter=0

name=input('Name:')
surname=input('Last Name:')
Class=input('Class Name:')

filelines=[]

Class=open(Class+'.txt','r')
line=Class.readline()
while line!='':
    Class.append(filelines)
    Class.close()

linecount=len(filelines)
for i in range(0,linecount):
    data=filelines[i].split(',')
Run Code Online (Sandbox Code Playgroud)

python attributeerror

7
推荐指数
1
解决办法
3万
查看次数

Python - 转换错误

我正在尝试编写一个程序,打印折扣后的总价格.如果价格paid结束100,它将会被淘汰20%.在程序结束时,我收到此错误:

if paid>=100:
    TypeError: unorderable types: str() >= int()
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

paid=input('How much did you pay? ')
if paid>=100:
    actualPay=100*1.25 #20% off total, 100/0.80 = 1.25
    print(actualPay)
Run Code Online (Sandbox Code Playgroud)

python python-3.x

1
推荐指数
1
解决办法
82
查看次数

标签 统计

python ×2

attributeerror ×1

python-3.x ×1