2017-11-09 4 views
-1

Ich bin sehr neu für Codierung und ich versuche, um Code in Python 3 folgendes Code:Brauchen Sie Hilfe versucht, in Python 3

How many students?: 4 
How many units?: 3 
What is the name of student 1?: John 
What did John get in unit 1?: 34 
34 out of 100 is a Fail. 
What did John get in unit 2?: 67 
67 out of 100 is a Credit. 
What did John get in unit 3?: 52 
52 out of 100 is a Pass. 
On average, John is getting a Pass. 

Dann, nachdem er dies tut, für alle vier Studenten, hat das Programm sagen: Die beste Punktzahl ist (Student Name) mit einer durchschnittlichen Punktzahl von (Student Score).

Das ist was ich bisher habe. Wie kann ich erreichen, dass die Schülerinformationen einzeln wie oben beschrieben durchlaufen werden? Meine kommt nacheinander heraus.

numStudent = int (input('Please enter number of students: ')) 
numUnit = int(input('Please enter the number of units for your course: ')) 

for i in range(numStudent): 
     studentName = input('Please enter students first name: ') 

for j in range(numUnit): 

    unitmark = int(input('what did' + ' ' + studentName + ' ' + 'get for unit:')) 

def calculateGrade(unitmark): 

    if unitmark <= 49: 
     Print(unitmark,"out of 100 You are failing") 
    elif unitmark <= 59: 
     return(unitmark,"out of 100 is a Pass") 
    elif unitmark <=69: 
     return(unitmark, "out of 100 is a Credit") 
    elif unitmark <= 79: 
     return(unitmark, "out of 100 is a Distinction") 
    elif unitmark <=100: 
     return(unitmark, "out of 100 is a High Distinction") 

print(calculateGrade(unitmark))   

totalGrade = numUnit + unitmark 

averageGrade = totalGrade/100 

print(round (averageGrade, 7)) 
+0

Pls zu akzeptieren, fixieren die Post. Es ist schlecht verständlich. – Abend

+0

Entschuldigung, wenn ich es eingefügt habe, kam es einfach so auf, wie repariere ich es? – Jules

+0

Eine Schnellsuche hilft Ihnen bei der Formatierung: [Wie formatieren Sie Code in Stack Overflow?] (Https://duckduckgo.com/?q=How+to+format+code+in+Stack+Overflow%3F) – halfer

Antwort

0

Hier ist die Lösung. Führen Sie in IDLE oder wenn Sie auf Linux sind führen Sie es im Terminal, zum Beispiel python3.6 ./grades.py (richtige Python-Version angeben und erstellen grades.py)

def get_grade(score, name=None): 
    if score <= 49: 
     grade = "You are failing" 
    elif score <= 59: 
     grade = "is a Pass" 
    elif score <= 69: 
     grade = "is a Credit" 
    elif score <= 79: 
     grade = "is a Distinction" 
    elif score <= 100: 
     grade = "is a High Distinction" 

    if not name: 
     print(score, "out of 100", grade) 
    else: 
     print('On average,', name, grade) 

num_students = int(input('How many students?: ')) 
num_units = int(input('How many units?: ')) 

students_db = {} 

for student_num in range(1, num_students+1): 
    student_name = input('\nWhat is the name of student %s?: ' % student_num) 

    current_student_total_scores = 0 
    for unit_num in range(1, num_units+1): 
     unitmark = int(input('\nWhat did %s get in unit %s?: ' % (student_name, unit_num))) 
     current_student_total_scores += unitmark 
     get_grade(unitmark) 

    avarage_score = current_student_total_scores/num_units 
    get_grade(avarage_score, student_name) 

    students_db.update({student_name: avarage_score}) 

name, avg_score = max(students_db.items(), key = lambda p: p[1]) 
print('\nThe top score is %s with an average score of %s' % (name, avg_score)) 

Vergessen Sie nicht die Antwort :)