Python字典键值Comp

2024-04-26 11:11:49 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我在自学Python,陷入了一个程序中。你知道吗

print('How many student recors you want to en')
number = raw_input()
number = int(number)
for increment in range(0,number) :
    student_increment= {}
    student_increment['marks'] =int(raw_input('Enter Marks') )
    student_increment['position']=0
    secondincrement = increment
    student_secondincrement = student_increment

for increment in range(0,number):
    for secondincrement in range(0,number):
        if int(student_increment['marks']) < int(student_secondincrement['marks']) :
          student_increment['position']=int(student_increment['position'])+1

for increment in range(0,number):
   print( student_increment) 

因此,首先我询问用户有多少个学生记录,然后将学生0、学生1等作为不同的字典作为学生增量。我取下所有的记录,然后比较不同词典中的标记,找出它们的位置(相当于在班级中的排名)。你知道吗

从我测试和尝试的内容来看,如果我的if语句没有执行,并且如果我尝试在#1comment的位置打印student#u secondincrement,它总是打印我的最后一个student#u increment条目。有人能告诉我为什么会这样吗?你知道吗


Tags: innumberforinputrawifpositionrange