2016-03-25 48 views
-5

我试图让Python打印一组特定的名称,成绩和字母等级,但是我会问及如何在“用户“输入号码和姓名。我要做的就是确保它有一个名字,数字等级,并以列表字母等级表示,这样 名称级信 乔98 鲍勃·56女性 等等...打印学生成绩,名单和字母等级

这里是我已经...

A_score = 90 
B_score = 80 
C_score = 70 
D_score = 60 
F_score = 50 

score1 = int(input('Enter score: ')) 
name1 = input('Enter name: ') 

score = int(input('Enter score: ')) 
name = input('Enter name: ') 

score = int(input('Enter score: ')) 
name = input('Enter name: ') 

score = int(input('Enter score: ')) 
name = input('Enter name: ') 

score = float(input('Enter score: ')) 
name = input('Enter name: ') 

# Print the table headings 
print('Name\tNumeric grade\tLetter grade') 
print('---------------------------------') 

#Print the names and grades 
for score in range(A_score, B_score, C_score): 
    print(name1, '\t', score1) 
+2

您的具体问题是什么?没有人会为你写代码。 **你得到什么输出**? – Meistro

+0

我想弄清楚什么是最好的方式来打印出名称,等级和字母等级。它会是一个def函数或其他东西? –

+0

这个问题令人困惑,因为有一些经验丰富的Python程序员会改变一些东西,但目前还不清楚哪些东西不适合你。请具体说明1)程序正在做什么,2)它不是什么。作为第一步,我建议您查看列表和字典以存储您的值。 –

回答

1

这是classes

班一个最好的例子,基本上这是用来创建对象的模板。对于你,你可以创建一个Student类,然后创建单个对象来表示每个学生。对象具有属性,如名称,等级和字母等级(在你的情况下)

下面是一个类可能看起来像你的一个小纲要。您需要根据具体应用对其进行更改,但这应该让您开始:

class Student(): 
    def __init__(self, name, grade, letter_grade): 
     self.name = name 
     self.grade = grade 
     self.letter_grade = letter_grade 

正如您所看到的,该类有三个属性。

>>> stdnt = Student("John",75.4,"C") 
>>> stdnt.name 
"John" 
>>> stdnt.grade 
75.4 

这应该给你如何将数据存储为您的学生(可能在Student对象的列表)的想法:你可以按如下方式使用此。

+1

很好的答案,并避免为他们做功课:P –