Question

this code is not working for me.. if enter 100 it is not showing the grades...

this code is not working for me.. if enter 100 it is not showing the grades insted asking for score again..

#Python program that prompts user to enter the valuesof grddes . Then calculate the total scores , #then find average of total score. Then find the letter grade of the average score. Display the #results on python console.
#grades.py
def main():
    #declare a list to store grade values
    grades=[]
    repeat=True
    #Set variables to zero
    total=0
    counter=0
    average=0
    gradeLetter=''
    #Repeat loop till user enters -1 to stop
    while repeat:
        #try-catch block to check if input is number
        try:
            value = int(input('Enter score : '))
            #Check if value is -1
            if value==-1:
                #set repeat to False to stop execution
                repeat=False
            else:
                #increment the counter by 1
                counter=counter+1
                #add value to total
                total=total+value
                #add value to grades
                grades.append(value)
        except ValueError:
            print('Invalid input')
    #calculate the average score
    average=total/counter
    #find the letter grade for average value
    if average>=92.50 and average<=100:
        gradeLetter='A'
    elif average>=88.5 and average<=92.49:
        gradeLetter='B+'
    elif average>=82.50 and average<=88.49:
        gradeLetter='B'
    else:
        gradeLetter = 'F'
    #Print total score
    print('Total Score',total)
    # Print average
    print('Average',average)
    # Print gradeLetter
    print('Letter Grade',gradeLetter)
#calling main method
main()
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the answer..

If you need score for each grade then below is the code

CODE:

def main():
#declare a list to store grade values
grades=[]
repeat=True
#Set variables to zero
total=0
counter=0
average=0
gradeLetter=''
#Repeat loop till user enters -1 to stop
while repeat:
#try-catch block to check if input is number
try:
value = int(input('\nEnter score : '))
#Check if value is -1
if value==-1:
#set repeat to False to stop execution
repeat=False
else:
#increment the counter by 1
counter=counter+1
#add value to total
total=total+value
#add value to grades
grades.append(value)
#calculate the average score
average=total/counter
#find the letter grade for average value
if average>=92.50 and average<=100:
gradeLetter='A'
elif average>=88.5 and average<=92.49:
gradeLetter='B+'
elif average>=82.50 and average<=88.49:
gradeLetter='B'
else: gradeLetter = 'F'
#Print total score
print('Total Score',total)
# Print average
print('Average',average)
# Print gradeLetter
print('Letter Grade',gradeLetter)
except ValueError:
print('Invalid input')
main()

OUTPUT:

If you want result at end of the grades then your code is working fine....Here is the outputs

OUTPUT:\

If you have any doubts please COMMENT...

If you understand the answer please give THUMBS UP..

Add a comment
Know the answer?
Add Answer to:
this code is not working for me.. if enter 100 it is not showing the grades...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please provide pseudocode for the following python program: class Student: def t(self,m1, m2, m3): tot= m1+m2+m3;...

    Please provide pseudocode for the following python program: class Student: def t(self,m1, m2, m3): tot= m1+m2+m3; average = tot/3; return average class Grade(Student): def gr(self,av): if av>90: print('A grade') elif (av<90) and (av>70): print('B grade') elif (av<70) and (av>50): print('C grade') else: print('No grade') print ("Grade System!\n") s=Student(); repeat='y' while repeat=='y': a=int(input('Enter 1st subject Grade:')) b=int(input('Enter 2nd subject Grade:')) c=int(input('Enter 3rd subject Grade:')) aver=s.t(a,b,c); g=Grade(); g.gr(aver); repeat=input("Do you want to repeat y/n=")

  • Write a Python Program Display the grades: Input: Enter the marks of the student Condition: Grade...

    Write a Python Program Display the grades: Input: Enter the marks of the student Condition: Grade A: Marks greater than 90 Grade B: Marks range from 81 to 90 Grade C: Marks range from 65 to 80 Fail: less than 65 Display the output. Example: Input: 95 Display: “student got Grade A” Input: 80 Display: “student got Grade C” Input: 64 Display: “student failed” Hint: Use else if (elif and logical operators)

  • 25.6 Ch. 03: Assign Midterm Grades (input, if, print) Assume the maximum midterm exam score is...

    25.6 Ch. 03: Assign Midterm Grades (input, if, print) Assume the maximum midterm exam score is 60. Write a program to ask the user to enter a student's score and print out a letter grade according to following table. Grade Weighted Score 904 or higher 808 or higher 700 or higher 600 or higher Lower than 605 A sample input/output interaction will look like the follows. Please enter a midterm score: 50 Grade for 50.0 will be B ACTIVITY 25.6.1:...

  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

  • Please make this Python code execute properly. User needs to create a password with at least...

    Please make this Python code execute properly. User needs to create a password with at least one digit, one uppercase, one lowercase, one symbol (see code), and the password has to be atleast 8 characters long. try1me is the example I used, but I couldn't get the program to execute properly. PLEASE INDENT PROPERLY. def policy(password): digit = 0 upper = 0 lower = 0 symbol = 0 length = 0 for i in range(0, len(password)): if password[i].isdigit(): # checks...

  • Professor Dolittle has asked some computer science students to write a program that will help him...

    Professor Dolittle has asked some computer science students to write a program that will help him calculate his final grades. Professor Dolittle gives two midterms and a final exam. Each of these is worth 100 points. In addition, he gives a number of homework assignments during the semester. Each homework assignment is worth 100 points. At the end of the semester, Professor Dolittle wants to calculate the median score on the homework assignments for the semester. He believes that the...

  • Java I am stuck on, enter a number grade: 9.8 ERROR: 9.8 and enter a number...

    Java I am stuck on, enter a number grade: 9.8 ERROR: 9.8 and enter a number grade: 10 ERROR: 10 Here is the specs ​​​​​​​ Write a class called Grades. Grades must have a main method (see example of what the main method does below). Grades are values between zero and 10 (both zero and 10 included), and are always rounded to the nearest half point (i.e. ALL GRADES entered in the system end in either .0 or .5). To...

  • Declare and initialize 4 Constants for the course category weights: The weight of Homework will be...

    Declare and initialize 4 Constants for the course category weights: The weight of Homework will be 15% The weight of Tests will be 35% The weight of the Mid term will be 20% The weight of the Fin al will be 30% Remember to name your Constants according to Java standards. Declare a variable to store the input for the number of homework scores and use a Scanner method to read the value from the Console. Declare two variables: one...

  • Write python code on computer, No handwritten code You will implement a program which asks the...

    Write python code on computer, No handwritten code You will implement a program which asks the user to enter scores of different courses in different semesters. The program should read the input and output some simple statistics 1. An example input string by the user is given below. Fal12016-coursel:82, course2:80,course3:85;Spring2018- course4:82;Fall2018-course5:85, course6:50, course7:78 Info from different semesters are separated by a ";", courses in each semester are separated by a,and score and corresponding course is separated by a, information of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT