我的代碼在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 = 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)
但是在我輸入分數(例如80、70、60)之後,結果是TypeError:'type'和'int'的例項之間不支援'>='。
最新回復
- 7月前1 #
产生列表
当您通過
score
到MyLib.calculate
,您需要遍歷每个元素(即每个int
)並建立本地變數nilai
包含使用者輸入的值。但是,
nilai
被重新分配给每个新輸入,這意味着您丢失了先前的值.此外,您永远不会返迴任何這些值,這意味着它们会永远丢失。score
然後傳遞给result
.然後將其迭代.在每次迭代中,n
等於int
因為那是列表中的唯一元素。您比较
int
到80行int
是type
型別的物件 .比较type
没有任何意義 設為80的整數。尝試更換
MyLib.calculate
与以下內容。然後您可以致電