Python 错误:'&燃气轮机=';在';类型';和';int';
我的代码在Test.py文件中Python 错误:'&燃气轮机=';在';类型';和';int';,python,Python,我的代码在Test.py文件中 name = input("enter your name :") id = int(input("enter your id :") score = [int]*3 MyLib.calculate(score) MyLib.result(name, id, score) 这是MyLib.py中的代码 def calculate (x) : n = 0 for n in x : nilai
name = input("enter your name :")
id = int(input("enter your id :")
score = [int]*3
MyLib.calculate(score)
MyLib.result(name, id, score)
这是MyLib.py中的代码
def calculate (x) :
n = 0
for n in x :
nilai = int(input("Input Your Score : "))
def result (a,b,c) :
n = 0
sum = 0
for n in c :
if n >= 80 and n <= 100 :
i = 4
x = "A"
elif n < 80 and n >= 70 :
i = 3
x = "B"
elif n < 70 and n >= 60 :
i = 2
x = "C"
elif n < 60 and n >= 50 :
i = 1
x = "D"
elif n < 50 and n >= 0 :
i = 0
x = "E"
sum += i
print("Your Name :",a)
print("Your ID :", b)
print("Your score number is ",n," and your score alphabet is ",x)
print("Your avg score is", sum)
def计算(x):
n=0
对于x中的n:
nilai=int(输入(“输入您的分数”))
def结果(a、b、c):
n=0
总和=0
对于c中的n:
如果n>=80且n=70:
i=3
x=“B”
如果n<70且n>=60:
i=2
x=“C”
如果n<60且n>=50:
i=1
x=“D”
如果n<50且n>=0:
i=0
x=“E”
总和+=i
打印(“您的姓名:”,a)
打印(“您的ID:,b”)
打印(“您的分数编号为”,n,“分数字母表为”,x)
打印(“您的平均分数为”,总和)
但在我输入分数(例如80、70、60)后,结果是TypeError:“>=”在“type”和“int”的实例之间不受支持。行
score = [int]*3
生成列表
[int, int, int]
当您将score
传递给MyLib.calculate
时,您迭代每个元素(即每个int
)并创建局部变量nilai
,该变量保存用户输入的值
但是,nilai
将重新分配给每个新输入,这意味着您将丢失以前的值。此外,您永远不会返回这些值中的任何一个,这意味着它们将永远丢失
得分
然后传递到结果
。然后对其进行迭代。在每次迭代中,n
等于int
,因为这是列表中唯一的元素
将int
与行中的80进行比较
if n >= 80 and n <= 100:
然后你可以打电话
scores = MyLib.calculate(3)
你的问题是什么?请澄清。我假设您正在寻找调试帮助,因此您需要提供一个。此代码不完整,但我可以放心地假设您导入MyLib。仅此而已,它不应该引发错误,但实际上它什么也不做,因为从未调用
result()
。查看是否需要更多提示。MyLib.calculate(score)
不会返回任何内容,也不会捕获其结果。你想在那里做什么?我不知道你说的不是你想要的是什么意思。相关的问题是它是否充分回答了您的问题。
scores = MyLib.calculate(3)