Wojtek Jakubowski
Wojtek Jakubowski

Reputation: 1

Counting average grades

in December I started working with Python and due to personal problems I cannot give it as much attention as I thought I could. I need help with my first basic project. I need to write a program that let's it's user write number of school grades and counts the average. I can start, write a list of grades but i cannot type a code that would count the average. I guess my problem lies in some basic knowledge which I lack of. I'd appreciate every help guys.

EDIT:

assignments = 5

x = [int(input('Ocena z cwiczenia {}: '.format(i+1))) for i in     range(assignments)]


finalGrade = int(input('Ocena z kolokwium: '))

average_assignment_grade = (sum(x) + finalGrade) / 6

print()
print('Średnia')


for number in range(1):
    print(format(average_assignment_grade, '.1f'))

A.append(average_assignment_grade);



grades_sum = sum(A)
grades_average = grades_sum / 6
if grades_sum < 3 print ("Przedmiot nie zaliczony")
else print("Przedmiot zaliczony")
File "<ipython-input-43-fe40b7e5825c>", line 23
if grades_sum < 3 print ("Przedmiot nie zaliczony")

So this is the code. As you can see I wanted it to show if the student has passed or not (it's in polish, "Przedmiot nie zaliczony" - not passed, "Przedmiot zaliczony" - passed) but I got invalid syntax error. I looked up my notes and I did everything like they say but obviously something is wrong and I have no idea what. Can you help now?

Upvotes: 0

Views: 243

Answers (1)

Lokesh Raj
Lokesh Raj

Reputation: 11

I have spotted 3 errors in your code and corrected them. 2 of them is indentation error(Error2 and Error3) and one of them is because you have not declared list before using it(Error1).

assignments = 5
x = [int(input('Ocena z cwiczenia {}: '.format(i+1))) for i in range(assignments)]

finalGrade = int(input('Ocena z kolokwium: '))

average_assignment_grade = (sum(x) + finalGrade) / 6

print()
print('Średnia')

for number in range(1):
    print(format(average_assignment_grade, '.1f'))

#error1 Before calling predefined function of list, you need to declare a list.
A = []
A.append(average_assignment_grade)



grades_sum = sum(A)
grades_average = grades_sum / 6

#Error2 In python, indentation is important. Scope of all conditional statements is 
#determine by indentation block.
if grades_sum < 3 : #Error2
    print ("Przedmiot nie zaliczony")
else: #Error3
    print("Przedmiot zaliczony")

Hope it solves your problem.

Upvotes: 1

Related Questions