我对编程很陌生,我只是在学习 Python。我在下面写的代码是一个程序,让你输入一个等级(例如 14/20 或 70 超过 100),然后给你一个从 A 到 E 的等级。基本上我想知道的是如果有一种方法可以“取出”列表中的整数,而不是一个一个地取出它们并将它们乘以 10、100 等等。
我总结一下:我希望等级 ["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")