Python Forum
Cant get grade part of code to work correctly - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Cant get grade part of code to work correctly (/thread-19651.html)



Cant get grade part of code to work correctly - Expel - Jul-08-2019

trying to get the grade part of the code to work, the rest seems to work fine

print("enter 5#s")
num1 = int(input())
num2 = int(input())
num3 = int(input())
num4 = int(input())
num5 = int(input())
numbers = [num1, num2, num3, num4, num5]
numsum = sum(numbers)
print("sum is:", numsum)
#Above list is working
def Average(numbers):
    return sum(numbers) / len (numbers)
print("AVG = ", round(Average(numbers), 2))
#determine letter grade below
score = int(Average(numbers)
if score >= 90:
  print('Grade is = A')
elif score >= 80:
  print('Grade is = B')    
elif score >= 70:
  print('Grade is = C')
elif score >= 60:
  print('Grade is = D')
else:
  print('Grade is = F')



RE: Cant get grade part of code to work correctly - rwahdan - Jul-08-2019

What part of the code is not working? I tried it and its working fine


RE: Cant get grade part of code to work correctly - Yoriz - Jul-08-2019

There is a ) missing from the end of score = int(Average(numbers)


RE: Cant get grade part of code to work correctly - Expel - Jul-08-2019

(Jul-08-2019, 10:09 PM)Yoriz Wrote: There is a ) missing from the end of score = int(Average(numbers)

And yet its always something so simple that gets looked over LOLOL
thank you XD


RE: Cant get grade part of code to work correctly - micseydel - Jul-09-2019

(Jul-08-2019, 10:09 PM)rwahdan Wrote: What part of the code is not working? I tried it and its working fine
Did you add the missing close-paren?


RE: Cant get grade part of code to work correctly - perfringo - Jul-10-2019

Suggestion regarding code.

Code should be DRY (don't repeat yourself). Every time you find yourself writing repeating rows you should stop and think what should you do differently. Don't use Python as typing machine, it's programming language.

You can ask user input with loop (requires 3.6 <= Python as f-string is used):

>>> answers = list()
>>> for i in range(5):
...     answers.append(int(input(f'Enter total of 5 numbers ({i+1}/5): ')))
... 
Enter total of 5 numbers (1/5): 4
Enter total of 5 numbers (2/5): 5
Enter total of 5 numbers (3/5): 5
Enter total of 5 numbers (4/5): 3
Enter total of 5 numbers (5/5): 4
>>> answers
[4, 5, 5, 3, 4]