Python Forum
Cant get grade part of code to work correctly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cant get grade part of code to work correctly
#1
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')
Reply
#2
What part of the code is not working? I tried it and its working fine
Reply
#3
There is a ) missing from the end of score = int(Average(numbers)
Reply
#4
(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
Reply
#5
(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?
Reply
#6
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]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I can't for the life of me get this basic If statement code to work CandleType1a 8 544 May-21-2024, 03:58 PM
Last Post: CandleType1a
  Why can I not see the code correctly in Python IDLE.? Trump 8 984 Apr-04-2024, 07:47 AM
Last Post: jonesphedra
  Remove part of the code hack3rcon 5 853 Jan-08-2024, 10:25 AM
Last Post: hack3rcon
  hi need help to make this code work correctly atulkul1985 5 1,035 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 853 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Beginner: Code not work when longer list raiviscoding 2 982 May-19-2023, 11:19 AM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 2,129 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Code used to work 100%, now sometimes works! muzicman0 5 1,669 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  color code doesn't work harryvl 1 1,044 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  Coding problem portfolio grade max70990 1 818 Dec-11-2022, 12:30 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020