Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you are going to write a program to enter a set of grades for students who have taken an exam, and then

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

In this assignment you are going to write a program to enter a set of grades for students who have taken an exam, and then generate a set of text-based bar graphs based on those grades. For example, if student Fred received a 78 on his exam, the line of output for Fred will be his name, his score, his letter grade, and then 78 copies of the | character (the vertical bar), padded appropriately with blanks. When your program runs, the expected output from Idle/Python will look like the following image (the top image is the whole output, the bottom is the left part zoomed up so you can see it more easily): Main Fred Sam Mary Bob Carol Sue >>Main () Fred Sam Mary Bob Carol Sue Mortimer 5 F III1 100 A ITII11I11I111 up the Assianment Type in the following program code framework just as you see it here, and then save it in your Python folder with Labl.py as the filename. Leave the gray areas blank; you will write new code there later. TYPE THIS IN WITH YOUR NAME, NOT MINE # William T. Verts -Assignment #1 def PadRight (S, N): Write new code here to return string S added on right with spaces to length N return S def PadLeft (S, N) Write new code here to return string S added on left with spaces to length N return S def GetGrade (Score) TYPE ALL THIS IN VERBATIM Write new code here to return a letter grade string appropriate to the value of variable Score return Result def Process (Name, Score): Write new code here to return a string S containing the name, score, letter grade, and histogram, all separated by the right number of spaces return S def Main: print (Process ("Fred", 78)) print (Process ("Sam", 23) print (Process ("Mary", 100)) print (Process ("Bob, 72)) print (Process ("Carol", 62)) print (Process "Sue", 85)) print (Process ("Mortimer", 5)) return Task #1-PadLeft and PadRight The PadRight function has two parameters: S (a string) and N (an int), and returns as its result the string S padded on the right with blanks until the length of S contains no fewer than N characters. The PadLeft function is identical to PadRight except that it adds blanks to the left side of the string For example, the string "Frog" is four characters long, so PadLeft ("Frog",7) would return the seven-character string"Frog" (with the extra blanks on the left) and PadRight ("Frog", 7) would return the seven-character string "Frog"(with the extra blanks on the right) ou wil e ofa rive Complete these functions, then test them from the >>>command line prompt with different strings and different lengths to make sure that they handle all possible cases. Common problems include "off- by-one" errors, where the number of blanks might be one too few or one too many-check this! The GetGrade function has one int parameter called Score. The function must return the one- character string "A" if Score is greater than or equal to 90, "B" if Score is greater than or equal to 80, "C" if Score is greater than or equal to 70, "D" if Score is greater than or equal to 60, and "E" otherwise. Complete this function, then test it with different values for Score to make sure it handles all five grade ranges correctly, including exactly 90, 80, 70, and 60. Task #3-Process The Process function has two parameters, Name and Score. Those parameters will be passed the name and the score for a particular student. For example, if the function is called as Process ("Fred", 78) then Name will contain the string "Fred" and Score will contain the integer 78 The Process function initializes a string S to the empty string, and then builds up and returns S as the value of the function, where S will contain the following items, in this order: Student's name, padded on the right to 10 characters (columns 1.. .10), Student's score, converted to a string, and padded on the left to 3 characters (columns Student's grade, padded on the left to 2 characters (columns 14...15), one extra blank (column 16), the correct number of vertical bar characters (columns 17...17+Score-1) 4 This function starts to build the string S by calling PadLeft, PadRight, and GetGrade with the appropriate actual parameters. This function then also requires the use of a loop to add to the string the correct number of vertical bar characters; for this assignment I want you to use a counter loop (a variable with a while-loop, and not a for-loop) Finish the function by writing code in the gray area to do all of this. The Process function must not contain anyprint statements. It returns its result as the value of the function; printing happens in the Main function Test your function by calling Process from the >command line prompt as Process ("Fred", 78) , which would return as the value of S the following string: Fred 78 Similarly, manually test Process ("Sam", 23) and Process ("Mary", 100) to verify that your function works correctly. Common problems include off-by-one" errors, where the number of vertical bars might be one too few or one too many-check this

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions