USING PYTHON, please complete the template below to solve these problems: Right-
ID: 3798785 • Letter: U
Question
USING PYTHON, please complete the template below to solve these problems:
Right-mouse click and save the file as project4.py.
#PROBLEM 1
def chop(l1,w):
list1 = l1
width = w
#YOUR CODE GOES HERE (indented)
return list1
#END YOUR CODE
#PROBLEM 2
def remove(l1,l2):
string1 = l1
string2 = l2
#YOUR CODE GOES HERE (indented)
return string1
#END YOUR CODE
Test cases for problem 1:
Please use this driver to test your code and make sure that it works as expected. Thanks
By right-mouse-click to save the file driver to the same directory as your project4.py. You can then run your code against our test cases through the terminal with the command"
python driver4_sample.py
Driver is below:
import subprocess
from project4 import *
file = open("tests4_sample.txt")
contents = file.readlines()
file.close()
source = open("project4.py")
lines = source.readlines()
source.close()
ctr = 0
bad = False
for line in lines:
if (".index(" in line or ".rindex(" in line or ".remove(" in line or ".count(" in line or ".find(" in line or ".slpit(" in line or ".rsplit(" in line or ".rindex(" in line or ".join(" in line or ".split(" in line or ".replace(" in line):
print "ERROR: on line " +str(ctr) + ": "+ line + " you are using a forbidden function or method. You are only allowed to use len(...) and/or .append(...) for this assignment."
bad = True
failed = False
ctr = 0
while ctr + 1< len(contents) and not bad:
pieces = contents[ctr].split(" ")
if pieces[0] == "chop":
result = chop(eval(pieces[1]),int(pieces[2]))
expected = contents[ctr+1].rstrip()
elif pieces[0] == "remove":
result = remove(pieces[1],pieces[2][:-1])
expected = contents[ctr+1].rstrip()
if (expected == str(result)):
print "passed test"
else:
print "For input " + contents[ctr].rstrip() + ", we expected '" + expected + "', but you got '" + str(result) + "'"
failed = True
ctr = ctr + 2
if not failed and not bad:
print "You passed all tests! Great work! PLEASE REMOVE ALL debug PRINT STATEMENTS FROM YOUR CODE before submitting to Marmoset."
result = subprocess.check_output("curl -k https://cs.gmu.edu/~kdobolyi/sparc/process.php?user=sparc_JjNcihjCCN7CpKRh-sample_ass4_1-COMPLETED", shell=True)
else:
print "At least one test case did not pass yet."
result = subprocess.check_output("curl -k https://cs.gmu.edu/~kdobolyi/sparc/process.php?user=sparc_JjNcihjCCN7CpKRh-sample_ass4_1-PROGRESS", shell=True)
Explanation / Answer
Hi,
For padding a list upto size N (in tis question it is width):
It would pad accordingly.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.