我對編程頗爲陌生,我只是在學習Python。我在下面寫的代碼是一個程序,可以讓你輸入一個等級(例如14/20或70,例如100),然後給你從A到E的等級。基本上我想知道的是如果有辦法「清除」列表中的整數,而不是一個接一個地將它們乘以10,100等等。從Python列表中獲取整數
我總結:我希望成績[「14 sur 20」]成爲a = 14和b = 20,而不必編寫我寫的所有代碼。
PS:我想我的代碼是太長,但我是新來的Python和我沒有足夠的知識還沒有把它縮短,所以不要太硬;)
import os
grade = input ("Entrez votre note :")
deter = []
redet = []
i = z = a = b = x = 0
while i < len(grade):
if grade[i] == "s" and grade[i+1] == "u" and grade [i+2] == "r" : #checking if the grade is written as " x sur y"
while z < i-1 : #building a list for the grade
deter.append (grade[z])
z += 1
z += 5 #jumping to the scale
while z < len(grade) : #building a list for the scale
redet.append (grade[z])
z += 1
elif grade[i] == "/" : #means grade is written as "x/y"
while z < i : #building a list for the grade
deter.append (grade[z])
z += 1
z += 1 #jumping to the scale
while z < len(grade) : #building a list for the scale
redet.append (grade[z])
z += 1
i += 1
redet = list (map(float, redet)) #converting to integers
deter = list (map(float, deter))
if len(deter)>1 :
y = 10**(len(deter)-1)
else:
y = 1
while x < len(deter) : #making variables
a = a + deter[x]*y
x += 1
y /= 10
x = 0
if len(redet)>1 :
y = 10**(len(redet)-1)
else :
y = 1
while x < len(redet) : #making variables
b = b + redet[x]*y
x += 1
y /= 10
grade = a/b
if grade >= 0.8 :
print("A")
elif grade >= 0.6 :
print("B")
elif grade >= 0.5 :
print("C")
elif grade >= 0.4 :
print("D")
elif grade <= 0.4 :
print("E")
os.system ("pause")
如果你瞭解考試是如何分級的,你通過! –