Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is python. please tell me how to do this task. Can I also write array in python? def PadRight (s, N): Write new code

image text in transcribed

image text in transcribed

this is python. please tell me how to do this task. Can I also write array in python?

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) Write new code here to return TYPE ALL THIS IN VERBATIM 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 Notice that there are four functions which need to be finished, PadRight, PadLeft, GetGrade, and Process. You can complete and debug each function in order, before working on the next function in the program. Function Main is finished as-is and must not be modified from what you see here. 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"rog" (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). However, the string "Froggies" is already longer than seven characters, so both PadLeft ("Froggies",7) and PadRight ("Froggies",7) would return the original string "Froggies" unchanged as the result. 7) returns the 7-character string: PadLeft ("Frog",7) PadRight ("Frog", 7) PadLeft ("Froggies", returns the 7-character ing:g 7) PadRight ("Froggies", 7, return the 8-character stri You will need to use the standard Python len function to ask about the current length of a string. 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions