Question

I have the below homework problem for a python programming class, and i really need some...

I have the below homework problem for a python programming class, and i really need some help!!

First, take a set of 6 grades from a user and average them. Provide the average to the user. You need to check to make sure the grades are within the normal range. If the grade is less than 0 or more than 100, issue a warning to the user. You don't need to take the grade again, just let the user know.

Second, ask the user how many grades they have. Ask for all the grades and again provide an average. Make sure to check that the grades are within the normal range as above and issue a warning to the user.

For any function you use, use the following comment block as before the function to document it. # function: name # purpose: # inputs: # returns:

Homework Answers

Answer #1

Code1:

def checkGrade(g):
if(g<0):
    print("Grade must be greater than 0.")
    return False
elif(g>100):
    print("Grade must be less than 100.")
    return False
else:
    return True
def avg(grades):
s = 0
for i in range(len(grades)):
    s+=grades[i]
return s/len(grades)

grades = []
i = 0
while(True):
if(i<5):
    print("Enter your grade ",i+1)
    g = int(input())
    if (checkGrade(g)):
      grades.append(g)
      i+=1
else:
    break
print("Entered grades are: ")
print(grades)
print("Average of all grades is : %d\n"%avg(grades))

Output:

Code2:

def checkGrade(g):
if(g<0):
    print("Grade must be greater than 0.")
    return False
elif(g>100):
    print("Grade must be less than 100.")
    return False
else:
    return True
def avg(grades):
s = 0
for i in range(len(grades)):
    s+=grades[i]
return s/len(grades)

grades = []
i = 0
n = int(input("Enter the number of grades you want to enter:"))
while(True):
if(i<n):
    print("Enter your grade ",i+1)
    g = int(input())
    if (checkGrade(g)):
      grades.append(g)
      i+=1
else:
    break
print("Entered grades are: ")
print(grades)
print("Average of all grades is : %d\n"%avg(grades))

Output:

Know the answer?
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
Similar Questions
COSC 1436 Programming Assignment 2 Programming Assignment 2 Refactoring is the process of taking existing code...
COSC 1436 Programming Assignment 2 Programming Assignment 2 Refactoring is the process of taking existing code and improving its design without changing the functionality. In this programming assignment, you are going to take your code from Programming Assignment 1 and refactor it so that it uses functions. The program should still do the following:  Get the name of a student  Get the name of three assignments  Get the grade of three assignments as integers  Calculates the...
Use the Python programming language to complete below (I need the New Answer for this, and...
Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!): Write a program to input an uncertain string S of words and space/tab Remove space/tab in S Remove identical words Sort all words in the order of a-z Print the output strings Example: Input String: "hello world and practice makes perfect and hello world again" Output String: "again and hello makes perfect practice world"...
I am a student taking python programming. Can this problem be modified using the define main...
I am a student taking python programming. Can this problem be modified using the define main method, def main()? import random #function definition #check for even and return 0 if even def isEven(number): if(number%2==0): return 0 #return 1 if odd else: return 1 #count variables even =0 odd = 0 c = 0 #loop iterates for 100 times for i in range(100): #generate random number n = random.randint(0,1000) #function call val = isEven(n) #check value in val and increment if(val==0):...
WRITE USING PYTHON PROGRAMMING THE CODE GIVEN BELOW HAS SOME ERRORS WHICH NEED TO BE SOLVED....
WRITE USING PYTHON PROGRAMMING THE CODE GIVEN BELOW HAS SOME ERRORS WHICH NEED TO BE SOLVED. ALSO THE 2 POINTS MENTIONED BELOW SHOULD BE PRESENT IN THE CODE Write a script that calculates the 3 longest words of a text stored in a file and print them from the longest to the smaller of the 3. Please note: 1. The name of the file is word_list.csv and it doesn’t need to be asked to the user (meaning the name will...
Using python, write the program below. Program Specifications: You are to write the source code and...
Using python, write the program below. Program Specifications: You are to write the source code and design tool for the following specification: A student enters an assignment score (as a floating-point value). The assignment score must be between 0 and 100. The program will enforce the domain of an assignment score. Once the score has been validated, the program will display the score followed by the appropriate letter grade (assume a 10-point grading scale). The score will be displayed as...
Stuck on some homework problems I need the problems answered that have a ? after the...
Stuck on some homework problems I need the problems answered that have a ? after the indicated section A computer store sells 7,200 boxes of storage drives annually. It costs the store $0.20 to store a box of drives for one year. Each time it reorders drives, the store must pay a $5.00 service charge for processing the order. 7200 boxes of storage drives are sold every year 0.2 is the cost of storing one box 5 is the cost...
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
write a code in python Write the following functions below based on their comments. Note Pass...
write a code in python Write the following functions below based on their comments. Note Pass is a key word you can use to have a function the does not do anything. You are only allowed to use what was discussed in the lectures, labs and assignments, and there is no need to import any libraries. #!/usr/bin/python3 #(1 Mark) This function will take in a string of digits and check to see if all the digits in the string are...
C Programming: I am working on the problem below and have got all of the code...
C Programming: I am working on the problem below and have got all of the code down, except for one part I can't figure out. The logic for the calculation where the the total at each shop is giving after each iteration of the loop. this is the formula I've got: ingredientPrice += ingredient1; It calculates the total for the first shop properly, but for the shops that follow it gives a cumulative total rather than the singular total for...
Python programming Write a program that prompts the user to input the three coefficients a, b,...
Python programming Write a program that prompts the user to input the three coefficients a, b, and c of a quadratic equationax2+bx+c= 0.The program should display the solutions of this equation, in the following manner: 1. If the equation has one solution, display ONE SOLUTION:, followed by the solution, displayed with4 digits printed out after the decimal place. 2. If the equation has two real solutions, display TWO REAL SOLUTIONS:, followed by the two solutions, each displayed with4 digits printed...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT