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
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):...
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...
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...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are pointers or constant pointers. Directions: Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS = 3; // may only be declared within the main function string students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Be sure to compile using g++ -std=c++11 helpWithGradesPtr.cpp Write a C++ program to run a menu-driven program with the...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm to work along with a worked exercise from Chapter 5. Use two different looping strategies for different purposes. Prior Task Completion: 1. Read Chapter 05. 2. View Chapter 05’s video notes. 3. As you view the video, work along with each code sample in PyCharm using the Ch 5 Iteration PPT Code Samples.zip. Important: Do not skip the process of following along with the...
I have a question for my homework that says to react the following compounds with one...
I have a question for my homework that says to react the following compounds with one equivalent of NBS with CCl4, and that they give only one major product. Then we have to explain why we gave our answers. I think this was just an accident that my professor left it out of the question, but wouldn't the reaction with NBS and CCl4 also need heat or light and peroxides to work? I've done the questions as if they were...
Hi. I need the third part of this problem, especially the second and third question. The...
Hi. I need the third part of this problem, especially the second and third question. The answer that are already in this site, are not complete. I appreciate your help. The weights of all one hundred (100) 9th graders at a school are measured, and it is found that the mean of all the measurements is 100 lbs., with a standard deviation of 15 lbs. Explain how you would use this information to determine the percentage of students who weighed...
PYTHON 1.      Complete the attached template program pattenrs.py to create and display a number of patterns. The...
PYTHON 1.      Complete the attached template program pattenrs.py to create and display a number of patterns. The program works with a single digit. The default value is 6, but user to change it as a menu selection. 2.      Program should display the patterns below. Additionally, you need to create your own pattern. 3.      Do not modify myPatterns6 driver. 4.      Make sure you document the program and its functions. 5.      PatternI is already implemented. 6.      Create five additional functions (similar to PatternI function) to implement Patterns II,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT