2016-08-31 53 views
0

只是一个初学者在Python的努力使GPA计算器作为一项基础性工程,但在语法得到一个错误:“预期的缩进块”Python的 - 预期的缩进块

import keyword 

classes = int(input("How many classes do you need to calculate?: ")) 

gpa = 0.0 

if classes == 1: 

    credits = int(input("Please enter the amount of credit hours of the class: ")) 
    grade = input("What was the grade you have earned?: ") 

    letter_points = letterGradeConversion() 

    print(letter_points) 

elif classes == 2: 

    credits = int(input("Please enter the amount of credit hours of the first class: ")) 
    grade = input("What was the grade you have earned?: ") 

    credits = int(input("Please enter the amount of credit hours of the second class: ")) 
    grade = input("What was the grade you have earned?: ") 


elif classes == 3: 

    credits = int(input("Please enter the amount of credit hours of the first class: ")) 
    grade = input("What was the grade you have earned?: ") 

    credits = int(input("Please enter the amount of credit hours of the second class: ")) 
    grade = input("What was the grade you have earned?: ") 

    credits = int(input("Please enter the amount of credit hours of the third class: ")) 
    grade = input("What was the grade you have earned?: ") 

elif classes == 4: 
    credits = int(input("Please enter the amount of credit hours of the first class: ")) 
    grade = input("What was the grade you have earned?: ") 

    credits = int(input("Please enter the amount of credit hours of the second class: ")) 
    grade = input("What was the grade you have earned?: ") 

    credits = int(input("Please enter the amount of credit hours of the third class: ")) 
    grade = input("What was the grade you have earned?: ")  

    credits = int(input("Please enter the amount of credit hours of the fourth class: ")) 
    grade = input("What was the grade you have earned?: ") 

else: 
    print("The max number of classes on this application is currently 4") 

def letterGradeConversion(): 
if grade == A: 
    gpa = gpa + 4  
elif grade == B: 
    gpa = gpa + 3 
elif grade == C: 
    gpa = gpa + 2 
elif grade == D: 
    gpa = gpa + 1 
elif grade == F: 
    gpa = gpa + 0 
else: 
    print("That is not a valid letter grade") 

不在代码:

iuashd; alksdjas; kjdha; slkjaskljsakdljas; ljlkjf; lkjsFLKAJSD; KJASD; KLK; jaS'LKDJ; ldjk;“DH'AHKL'ASJKLASJKQIOWJWQOIH

+0

这是一个好主意,张贴完整的堆栈跟踪,因为它包含描述错误发生在哪里的信息 –

+0

顺便说一句,你应该尝试重新组织你的逻辑,所以你不要没有所有的重复。请参阅[不要重复自己](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)。这将使您的代码更紧凑,更易于调试和维护。 –

回答

3

你的函数定义(一切def ... :后)必须缩进。的

def letterGradeConversion(): 
if grade == A: 
    gpa = gpa + 4 
...