Question

Having trouble with python!

Write a program to build a list of grades, print them out, add to them and count occurrences, and find the amount of the 2-digit grade values. Here are the criteria a) Your program “L6QI initials.py must start with a commented ID Box AND include a comment that indicates the e of the program. EACH of the five functions in your program must state its purpose in comments too The main function in your program must be named: test_grades ).It has been provided for you. Copy this function into your program EXACTLY as written: # Main function - Test all of the helper functions def test_grades ): grade-list create-grades (11) print_rows (grade_list) add grade (grade 1ist) print_rows (grade_list) print (Amount of 2-digit valuescount_grades (grade_list)) As you can see, test_grades calls FOUR helper functions namely: create grades (amount): Create and return a list of amount randomly selected integers between (and including) 0 and 100 print rows (grade list): ng 4 space separated values in each row. The last Print all of qrade list showi row may have fewer than 4 values in it. add_grade (grade_list): Prompt the user for a grade between (and including) 0 and 100 and append it to grade list. Count how many times the grade occurs in grade_list and print out the result. NOTE: Error checking is not required for this input. count_grades (grade_list): Calculate and return the amount of 2-digit grades in grade_list (ie. grades between 10 and99). Assume grade_list will contain at least one value.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

The below Pythonic 3 Code is written to satify all the criteria mentioned in the question.

Test this program with giving test_grades() at the command line and find the result!!

import random
#Main Function - Test all of the helper functions
def test_grades():
grade_list=create_grades(11)
print_rows(grade_list)

add_grade(grade_list)
print_rows(grade_list)

print("Amount of 2-digit values =",count_grades(grade_list))

#Create a list of random selected integers with "amount" as length of the list
def create_grades(amount):
list1=[]
for x in range(amount):
list1.append(random.randint(0,100))
return list1

#print the list with 4 space separated values in a row
def print_rows(grade_list):
for i in range(len(grade_list)):
if i%4==0:
print()
print (grade_list[i],end=' ')
print()

#Prompt user for a grade and append to the list, besides counting the occurrence of the grade in the list
def add_grade(grade_list):
grade=int(input("Enter a grade between 0 and 100:"))
grade_list.append(grade)
print("%d occurs %d times " %(grade,grade_list.count(grade)))

#Calculate and return the amount of 2-digit grades in the list
def count_grades(grade_list):
count=0
for i in grade_list:
if i >=10 and i<=99:
count+=1
return count

Happy coding,

Thanks and Regards,

Hema.

Add a comment
Know the answer?
Add Answer to:
Having trouble with python! Write a program to build a list of grades, print them out,...
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
  • Exercise 6: Program exercise for 2D List Write a complete Python program including minimal comments (file...

    Exercise 6: Program exercise for 2D List Write a complete Python program including minimal comments (file name, your name, and problem description) that solves the following problem with the main function: Problem Specification: The following code reads values from the file object infile and stores them in the 2d list table2: (It assumes that each line contains values of elements in each row and the values are whitespace separated.) table2 = [] for line in infile: row=line.split() intRow = []...

  • ### Question in python code, write the code on the following program: def minmaxgrades(grades, names): """...

    ### Question in python code, write the code on the following program: def minmaxgrades(grades, names): """ Computes the minimum and maximujm grades from grades and creates a list of two student names: first name is the student with minimum grade and second name is the student with the maximum grade. grades: list of non-negative integers names: list of strings Returns: list of two strings """ def main(): """ Test cases for minmaxgrades() function """ input1 = [80, 75, 90, 85,...

  • (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that...

    (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that you have been provided on Canvas. That file has a name and 3 grades on each line. You are to ask the user for the name of the file and how many grades there are per line. In this case, it is 3 but your program should work if the files was changed to have more or fewer grades per line. The name and...

  • Python please help! Thanks you Write a code to get an unlimited number of grades from...

    Python please help! Thanks you Write a code to get an unlimited number of grades from the user (the user can press enter to finish the grades input, or use a sentinel, for example-1), and then calculate the GPA of all the grades and displays the GPA To do this you might need some help. Try to follow the following process (and check your progress by printing different values to make sure they are as they supposed to be): 1-...

  • Homework 1 - Simple Array Handling Write a working C++ program to ask the user for...

    Homework 1 - Simple Array Handling Write a working C++ program to ask the user for a set of grades which are to be stored in an array in increasing sequence. The user must first provide the number which represents the count of all grades to be provided. For example, if there will be 10 grades, the user is first prompted to provide the number 10. Subsequently, each grade is provided, one at a time. Allow for a maximum of...

  • C++ Use C++ functions and build a program that does the most basic job all students...

    C++ Use C++ functions and build a program that does the most basic job all students have to contend with, process the grades on a test and produce a summary of the results. The big wrinkle is, it should be a multi-file program. -Requires three simple things: Figure out the best score of all scores produced Figure out the worst score of all scores produced Assign a letter grade for each score produced Complete this lab by writing three functions....

  • python program- ---create a function that returns the longest word inside a list of words ---create...

    python program- ---create a function that returns the longest word inside a list of words ---create a function with two parameters (phrase,wordList) that returns a count of how many words are spelled incorrectly that cannot be found in wordList (a list of words) for both you can only use these functions --- append, len, str, float, range, strip, split, int.

  • Write a program (a3.py) that has 3 function definitions: magic-sequential(), magic-binary(), and main(). You will write...

    Write a program (a3.py) that has 3 function definitions: magic-sequential(), magic-binary(), and main(). You will write the code for the above functions. Both magic functions (magic-sequential() and magic-binary()) will look for a magic index in a given sorted list of distinct integers. A magic index in a list myList[0 ... n-1] is defined to be an index i such that myList[i] = i . Both functions receive the list as a parameter and return an integer: either the magic index,...

  • Write a C++ program that computes student grades for an assignment as a percentage given each...

    Write a C++ program that computes student grades for an assignment as a percentage given each student's score and the total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath header file and displayed as a percentage. You must also display the floating-point result up to 5 decimal places. You must use at least 2 functions: one to print the last name of the student and another function to...

  • This needs to be in python, however, I am having trouble with the code. Is there...

    This needs to be in python, however, I am having trouble with the code. Is there any way to use the code that I already have under the main method? If so, what would be the rest of the code to finish it? #Create main method def main(): #Create empty list list=[] #Display to screen print("Please enter a 3 x 4 array:") #Create loop for rows and have each entered number added to list for i in range(3): list.append([int(x) for...

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