You are an adept, highly detail oriented grading assistant. Given the instructor code and rubric grade the student code. Note, it doesn't have to be an exact efficient match instead it adheres to the rubric guidelines.
Rubric:
"""
Problem A
General point breakdown
Getting and validating side length: 5 points
Calling print_square() correctly: 5 points
print_square(): 40 points
Correct number of rows: 15 points
Correct number of columns: 15 points
Printing spaces instead of asterisks in the interior: 10 points
Notes
Do take off points for poor variable names. Random unrelated names should lose 5 points. Single or two character names that don't have obvious meaning should lose 2 points.
Take off 3 points for input and/or 3 points for output messages if they don’t conform to the required messages and continue to provide feedback that more points may be lost in the future.
Minor typos should typically result in 2 points off each.
There are several ways to solve print_square(). My solution is just one of them. Students don't have to solve it the same way so long as they get the same results in a sane way. For example, some students might print the first and last rows separately from the "middle" rows. Others might use a list of lists or strings with each character then print that out after filling it up, etc.
My solution also uses a function to get the user input. That's not required.
Specific feedback
-3, user prompt messages don’t match the required message formats. See assignment for the required message format.
-3, output message doesn’t match the required message format. See assignment for the required message format.
-50, nothing submitted for this problem.
-5, did not validate that the side length is at least 1.
-10, printed a "full" filled-in square rather than a hollow one. Think about conditions you could test that would allow you to print a space " " rather than a "*" if you aren't on the edge of the square.
-5, not supposed to print spaces between each asterisk in general.
-10, the number of asterisks/spaces in each row is supposed to be equal to the side length parameter.
-10, the number of asterisks in each column is supposed to be equal to the side length parameter.
-10, do not use global scope variables (those in the top-level program) inside functions unless they are passed in as parameters.
-10, print_square() should not be prompting the user for the side length - that needs to happen in the top-level program, then pass the side length to print_square() as an argument.
"""
Instructor Code Sample:
code
import sys
def get\_positive\_int(name):
x = int(input(f"Enter {name}: "))
if x <= 0:
print(f"{name} must be positive!")
sys.exit()
return x
def print\_square(length):
row = 1
while row <= length:
col = 1
while col <= length:
if 1 < row < length and 1 < col < length:
print(" ", end="")
else:
print("\*", end="")
col += 1
print()
row += 1
side = get\_positive\_int("side length")
print\_square(side)
Student Code:
code
import sys
def print\_square(side):
a = 1
while a <= side:
i = 1
if a == 1 or a == side:
while i < side:
print("\*",end="")
i += 1
else:
print("\*",end="")
x = 0
while x < (side - 2):
print(" ",end="")
x += 1
print("\*")
a += 1
user\_input = int(input("Enter side length: "))
if user\_input <= 0:
print("side length must be positive!")
sys.exit()
print\_square(user\_input)
Assistant
Grading based on the rubric:
Getting and validating side length: 5 points (The student code validates side length and prints an appropriate error message.)
Calling print_square() correctly: 5 points (The student code calls the print_square() function with the user input as an argument.)
print_square(): 40 points
Correct number of rows: 15 points (The student code prints the correct number of rows for the given side length.)
Correct number of columns: 15 points (The student code prints the correct number of columns for the given side length.)
Printing spaces instead of asterisks in the interior: 10 points (The student code prints spaces in the interior of the square correctly.)
Notes deductions:
2 points off for using single-character variable names that don't have obvious meaning (a, i, x).
Input/output message deductions:
3 points off for not using the required input message format ("Enter side length: " instead of "Enter side length: ").
Total points: 95 out of 100
Specific feedback:
-2, using single-character variable names that don't have obvious meaning. Use more descriptive names for better readability.
-3, user input message doesn’t match the required message format. See assignment for the required message format.
User
code
import sys
#let user type in their input
#sanitize the input to make them all positive integers
user\_input = int(input("Enter side length: "))
if user\_input < 1:
print("side length must be positive!")
sys.exit()
#create the function print\_square
def print\_square (var):
#print the first line
print(var \* "\*")
#print the middle lines with spaces and \*
middle\_space = "\*" + " "\*(var-2) + "\*"
i=0
#print a single \* if the input is 1
if var == 1:
None
#convert the rest of the positive integer input into square
else:
while i < var-2:
print(middle\_space)
i+=1
print(var \* "\*")
#print out the result
print\_square (user\_input)
Assistant
Grading based on the rubric:
Getting and validating side length: 5 points (The student code validates side length and prints an appropriate error message.)
Calling print_square() correctly: 5 points (The student code calls the print_square() function with the user input as an argument.)
print_square(): 40 points
Correct number of rows: 15 points (The student code prints the correct number of rows for the given side length.)
Correct number of columns: 15 points (The student code prints the correct number of columns for the given side length.)
Printing spaces instead of asterisks in the interior: 10 points (The student code prints spaces in the interior of the square correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format ("Enter side length: " instead of "Enter side length: ").
Total points: 97 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
User
import sys
#do the print_square function
def print_square(side_length):
length = 0
while length < side_length:
width = 0
while width < side_length:
#printing out the full rows/columns
if length == 0 or width == 0 or length == (side_length-1) or width == (side_length-1):
print("*",end="")
else:
#print out the hollow rows/columns
print(" ", end="")
width += 1
print()
length += 1
#asking the user for input
side_length = int(input("Enter side length: "))
if side_length <= 0:
print("side length must be positive!")
sys.exit()
else:
print_square(side_length)
Assistant
Grading based on the rubric:
Getting and validating side length: 5 points (The student code validates side length and prints an appropriate error message.)
Calling print_square() correctly: 5 points (The student code calls the print_square() function with the user input as an argument.)
print_square(): 40 points
Correct number of rows: 15 points (The student code prints the correct number of rows for the given side length.)
Correct number of columns: 15 points (The student code prints the correct number of columns for the given side length.)
Printing spaces instead of asterisks in the interior: 10 points (The student code prints spaces in the interior of the square correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format ("Enter side length: " instead of "Enter side length: ").
Total points: 97 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
User
import sys
#def function
def print_square(side):
lines = 1
vertical = 1
while lines <= side:
if lines == 1 or lines == side:
stars = 0
while stars < side:
print("*", end = "")
stars += 1
else:
stars = 1
while stars <= side:
if stars == 1 or stars == side:
print("*", end = "")
else:
print(" ", end = "")
stars += 1
print()
lines += 1
#ask for user input and check if positive
side = int(input("Enter side length: "))
if side <= 0:
print("side length must be positive!")
sys.exit()
#call function
print_square(side)
Assistant
Grading based on the rubric:
Getting and validating side length: 5 points (The student code validates side length and prints an appropriate error message.)
Calling print_square() correctly: 5 points (The student code calls the print_square() function with the user input as an argument.)
print_square(): 40 points
Correct number of rows: 15 points (The student code prints the correct number of rows for the given side length.)
Correct number of columns: 15 points (The student code prints the correct number of columns for the given side length.)
Printing spaces instead of asterisks in the interior: 10 points (The student code prints spaces in the interior of the square correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format ("Enter side length: " instead of "Enter side length: ").
Total points: 97 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
User
import sys
def print_square(x):
top = "*"*x
bottom = "*"*x
print(top)
for _ in range(x-2):
sides = ("*" + " "*(x-2) + "*")
print(sides)
print(bottom)
length = int(input("Enter side length: "))
if length <= 0:
print("side length must be positive!")
sys.exit()
print_square(length)
Assistant
Grading based on the rubric:
Getting and validating side length: 5 points (The student code validates side length and prints an appropriate error message.)
Calling print_square() correctly: 5 points (The student code calls the print_square() function with the user input as an argument.)
print_square(): 40 points
Correct number of rows: 15 points (The student code prints the correct number of rows for the given side length.)
Correct number of columns: 15 points (The student code prints the correct number of columns for the given side length.)
Printing spaces instead of asterisks in the interior: 10 points (The student code prints spaces in the interior of the square correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format ("Enter side length: " instead of "Enter side length: ").
Total points: 97 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
User
You are an adept, highly detail oriented grading assistant. Given the instructor code and rubric grade the student code. Note, it doesn't have to be an exact efficient match instead it adheres to the rubric guidelines.
Rubric:
"""
Problem A
General point breakdown
Getting and validating side length: 5 points
Calling print_square() correctly: 5 points
print_square(): 40 points
Correct number of rows: 15 points
Correct number of columns: 15 points
Printing spaces instead of asterisks in the interior: 10 points
Notes
Do take off points for poor variable names. Random unrelated names should lose 5 points. Single or two character names that don't have obvious meaning should lose 2 points.
Take off 3 points for input and/or 3 points for output messages if they don’t conform to the required messages and continue to provide feedback that more points may be lost in the future.
Minor typos should typically result in 2 points off each.
There are several ways to solve print_square(). My solution is just one of them. Students don't have to solve it the same way so long as they get the same results in a sane way. For example, some students might print the first and last rows separately from the "middle" rows. Others might use a list of lists or strings with each character then print that out after filling it up, etc.
My solution also uses a function to get the user input. That's not required.
Specific feedback
-3, user prompt messages don’t match the required message formats. See assignment for the required message format.
-3, output message doesn’t match the required message format. See assignment for the required message format.
-50, nothing submitted for this problem.
-5, did not validate that the side length is at least 1.
-10, printed a "full" filled-in square rather than a hollow one. Think about conditions you could test that would allow you to print a space " " rather than a "*" if you aren't on the edge of the square.
-5, not supposed to print spaces between each asterisk in general.
-10, the number of asterisks/spaces in each row is supposed to be equal to the side length parameter.
-10, the number of asterisks in each column is supposed to be equal to the side length parameter.
-10, do not use global scope variables (those in the top-level program) inside functions unless they are passed in as parameters.
-10, print_square() should not be prompting the user for the side length - that needs to happen in the top-level program, then pass the side length to print_square() as an argument.
"""
Instructor Code Sample:
code
import sys
def get\_positive\_int(name):
x = int(input(f"Enter {name}: "))
if x <= 0:
print(f"{name} must be positive!")
sys.exit()
return x
def print\_square(length):
row = 1
while row <= length:
col = 1
while col <= length:
if 1 < row < length and 1 < col < length:
print(" ", end="")
else:
print("\*", end="")
col += 1
print()
row += 1
side = get\_positive\_int("side length")
print\_square(side)
Assistant
Grading based on the rubric:
Getting and validating side length: 5 points (The student code validates side length and prints an appropriate error message.)
Calling print_square() correctly: 5 points (The student code calls the print_square() function with the user input as an argument.)
print_square(): 40 points
Correct number of rows: 15 points (The student code prints the correct number of rows for the given side length.)
Correct number of columns: 15 points (The student code prints the correct number of columns for the given side length.)
Printing spaces instead of asterisks in the interior: 10 points (The student code prints spaces in the interior of the square correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format ("Enter side length: " instead of "Enter side length: ").
Total points: 97 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
User
import sys
define function to generate my square given side length input
def print_square(side_length):
i = 2
print(f"{'*' * side_length}")
while i < side_length:
print(f"{'*' + ' ' * (side_length - 2) + '*'}")
i += 1
print(f"{'*' * side_length}", end="") ##, ??
my output doesn't change when I add this second print argument
(as recommended by the assignment instructions... have I done
something wrong? what does this do differently than without it?
get side length input from user
side_length = int(input("Enter side length: "))
if side_length <= 0:
print("side length must be positive!")
sys.exit()
run the function to generate the square
print_square(side_length)
Assistant
Grading based on the rubric:
Getting and validating side length: 5 points (The student code validates side length and prints an appropriate error message.)
Calling print_square() correctly: 5 points (The student code calls the print_square() function with the user input as an argument.)
print_square(): 40 points
Correct number of rows: 15 points (The student code prints the correct number of rows for the given side length.)
Correct number of columns: 15 points (The student code prints the correct number of columns for the given side length.)
Printing spaces instead of asterisks in the interior: 10 points (The student code prints spaces in the interior of the square correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format ("Enter side length: " instead of "Enter side length: ").
Total points: 97 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
Regarding the question about the "end" parameter, the student's code is already correct. The "end" parameter in the print function is used to specify the string that is printed at the end of the line. By default, it is set to "\n", which is a newline character. In the student's code, end="" is used in the last print statement to prevent an additional newline at the end of the square output. However, since it is the last line of output, there's no visible difference in this case, whether end="" is included or not. It won't affect the final output or grading, and the student's code is correct.
User
You are an adept, highly detail oriented grading assistant. Given the instructor code and rubric grade the student code. Note, it doesn't have to be an exact efficient match instead it adheres to the rubric guidelines.
Rubric:
"""
Problem A
General point breakdown
Getting and validating side length: 5 points
Calling print_square() correctly: 5 points
print_square(): 40 points
Correct number of rows: 15 points
Correct number of columns: 15 points
Printing spaces instead of asterisks in the interior: 10 points
Notes
Do take off points for poor variable names. Random unrelated names should lose 5 points. Single or two character names that don't have obvious meaning should lose 2 points.
Take off 3 points for input and/or 3 points for output messages if they don’t conform to the required messages and continue to provide feedback that more points may be lost in the future.
Minor typos should typically result in 2 points off each.
There are several ways to solve print_square(). My solution is just one of them. Students don't have to solve it the same way so long as they get the same results in a sane way. For example, some students might print the first and last rows separately from the "middle" rows. Others might use a list of lists or strings with each character then print that out after filling it up, etc.
My solution also uses a function to get the user input. That's not required.
Specific feedback
-3, user prompt messages don’t match the required message formats. See assignment for the required message format.
-3, output message doesn’t match the required message format. See assignment for the required message format.
-50, nothing submitted for this problem.
-5, did not validate that the side length is at least 1.
-10, printed a "full" filled-in square rather than a hollow one. Think about conditions you could test that would allow you to print a space " " rather than a "*" if you aren't on the edge of the square.
-5, not supposed to print spaces between each asterisk in general.
-10, the number of asterisks/spaces in each row is supposed to be equal to the side length parameter.
-10, the number of asterisks in each column is supposed to be equal to the side length parameter.
-10, do not use global scope variables (those in the top-level program) inside functions unless they are passed in as parameters.
-10, print_square() should not be prompting the user for the side length - that needs to happen in the top-level program, then pass the side length to print_square() as an argument.
"""
Instructor Code Sample:
code
import sys
def get\_positive\_int(name):
x = int(input(f"Enter {name}: "))
if x <= 0:
print(f"{name} must be positive!")
sys.exit()
return x
def print\_square(length):
row = 1
while row <= length:
col = 1
while col <= length:
if 1 < row < length and 1 < col < length:
print(" ", end="")
else:
print("\*", end="")
col += 1
print()
row += 1
side = get\_positive\_int("side length")
print\_square(side)
Assistant
Grading based on the rubric:
Getting and validating side length: 5 points (The student code validates side length and prints an appropriate error message.)
Calling print_square() correctly: 5 points (The student code calls the print_square() function with the user input as an argument.)
print_square(): 40 points
Correct number of rows: 15 points (The student code prints the correct number of rows for the given side length.)
Correct number of columns: 15 points (The student code prints the correct number of columns for the given side length.)
Printing spaces instead of asterisks in the interior: 10 points (The student code prints spaces in the interior of the square correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format ("Enter side length: " instead of "Enter side length: ").
Total points: 97 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
User
You are an adept, highly detail oriented grading assistant. Given the instructor code and rubric grade the student code. Note, it doesn't have to be an exact efficient match instead it adheres to the rubric guidelines.
Rubric:
"""
Problem A
General point breakdown
Getting and validating side length: 5 points
Calling print_square() correctly: 5 points
print_square(): 40 points
Correct number of rows: 15 points
Correct number of columns: 15 points
Printing spaces instead of asterisks in the interior: 10 points
Notes
Do take off points for poor variable names. Random unrelated names should lose 5 points. Single or two character names that don't have obvious meaning should lose 2 points.
Take off 3 points for input and/or 3 points for output messages if they don’t conform to the required messages and continue to provide feedback that more points may be lost in the future.
Minor typos should typically result in 2 points off each.
There are several ways to solve print_square(). My solution is just one of them. Students don't have to solve it the same way so long as they get the same results in a sane way. For example, some students might print the first and last rows separately from the "middle" rows. Others might use a list of lists or strings with each character then print that out after filling it up, etc.
My solution also uses a function to get the user input. That's not required.
Specific feedback
-3, user prompt messages don’t match the required message formats. See assignment for the required message format.
-3, output message doesn’t match the required message format. See assignment for the required message format.
-50, nothing submitted for this problem.
-5, did not validate that the side length is at least 1.
-10, printed a "full" filled-in square rather than a hollow one. Think about conditions you could test that would allow you to print a space " " rather than a "*" if you aren't on the edge of the square.
-5, not supposed to print spaces between each asterisk in general.
-10, the number of asterisks/spaces in each row is supposed to be equal to the side length parameter.
-10, the number of asterisks in each column is supposed to be equal to the side length parameter.
-10, do not use global scope variables (those in the top-level program) inside functions unless they are passed in as parameters.
-10, print_square() should not be prompting the user for the side length - that needs to happen in the top-level program, then pass the side length to print_square() as an argument.
"""
Instructor Code Sample:
code
import sys
def get\_positive\_int(name):
x = int(input(f"Enter {name}: "))
if x <= 0:
print(f"{name} must be positive!")
sys.exit()
return x
def print\_square(length):
row = 1
while row <= length:
col = 1
while col <= length:
if 1 < row < length and 1 < col < length:
print(" ", end="")
else:
print("\*", end="")
col += 1
print()
row += 1
side = get\_positive\_int("side length")
print\_square(side)
Assistant
Grading based on the rubric:
Getting and validating side length: 3 points (The student code validates side length but does it inside the print_square() function instead of the top-level program. The error message is not consistent with the rubric.)
Calling print_square() correctly: 2 points (The student code doesn't call the print_square() function with user input as an argument, and instead hardcodes the value 5.)
print_square(): 40 points
Correct number of rows: 15 points (The student code prints the correct number of rows for the given side length.)
Correct number of columns: 15 points (The student code prints the correct number of columns for the given side length.)
Printing spaces instead of asterisks in the interior: 10 points (The student code prints spaces in the interior of the square correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format.
3 points off for not providing an output message format.
Total points: 55 out of 100
Specific feedback:
-3, user input message is missing. See assignment for the required message format.
-3, output message is missing. See assignment for the required message format.
-2, print_square() should not have the side length validation inside the function. Validation should happen in the top-level program before calling print_square().
-2, print_square() should be called with user input as an argument, not a hardcoded value.
User
You are an adept, highly detail oriented grading assistant. Given the instructor code and rubric grade the student code. Note, it doesn't have to be an exact efficient match instead it adheres to the rubric guidelines.
Rubric:
"""
General point breakdown
Main function: 15 points
Looping against the difference in guesses: 10 points
Calculating each next guess: 5 points
Returning the best guess: 5 points
Notes:
Do take off points for poor variable names. Random unrelated names should lose 5 points. Single or two character names that don't have obvious meaning should lose 2 points.
Take off 3 points for input and/or 3 points for output messages if they don’t conform to the required messages and continue to provide feedback that more points may be lost in the future.
Minor typos should typically result in 2 points off each.
My solution uses a function to get the user input. That's not required.
Note that students will lose 40 points if they use math.sqrt() or math.pow(). Another 10 points if they use abs() or math.abs().
Specific feedback
-3, user prompt message doesn’t match the required message format. See assignment for the required message format.
-3, output messages don’t match the required message formats. See assignment for the required message format.
-50, nothing submitted for this problem.
-40, can't use math.sqrt(), math.pow(), or any related built-in math functions.
-10, have to write your own absolute_value() function, can't use abs() or math.abs().
-5, the final estimate is supposed to be printed to 5 decimal places.
-10, do not use global scope variables (those in the top-level program) inside functions unless they are passed in as parameters.
-5, the loop in square_root() has to use the absolute_value() function to make sure the difference in estimates is positive.
-10, your loop in square_root() isn't right. You have to check if the difference between the two most recent estimates is greater than the tolerance and keep looping if so.
-10, you have to use two variables to track the current estimate and the better estimate each time through the loop so that you can stop the loop when the two estimates are close enough (less than the tolerance).
-5, have to return the current best estimate, not the previous best estimate.
-10, have to return the estimate at the end of the square_root() function, not print it out in the function.
Instructor Sample Code:
code
Assistant
Grading based on the rubric:
Main function: 15 points
Getting and validating inputs: 5 points (The student code validates inputs correctly.)
Calling square_root() correctly: 5 points (The student code calls square_root() correctly with appropriate arguments.)
Printing results correctly: 4 points (The student code prints the result correctly, but not to 5 decimal places as required.)
absolute_value() function: 5 points (The student code defines a correct absolute_value() function.)
square_root() function: 30 points
Having correct two parameters: 10 points (The student code has the correct two parameters in square_root() function.)
Looping against the difference in guesses: 10 points (The student code loops correctly against the difference in guesses.)
Calculating each next guess: 5 points (The student code calculates the next guess correctly.)
Returning the best guess: 5 points (The student code returns the best guess correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format.
3 points off for not providing the required output message format.
Total points: 89 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
-3, output messages don’t match the required message formats. See assignment for the required message format.
-1, the final estimate is supposed to be printed to 5 decimal places.
User
def absolute_value(x):
if x < 0:
return (x) / -1
else:
return x
if user_tolerance <= 0:
print("tolerance must be positive!")
sys.exit()
babylonian = square_root(user_x,user_tolerance)
print(f"Square root = {babylonian:.10f}")
Assistant
Grading based on the rubric:
Main function: 15 points
Getting and validating inputs: 5 points (The student code validates inputs correctly.)
Calling square_root() correctly: 5 points (The student code calls square_root() correctly with appropriate arguments.)
Printing results correctly: 5 points (The student code prints the result correctly to 5 decimal places as required.)
absolute_value() function: 5 points (The student code defines a correct absolute_value() function.)
square_root() function: 30 points
Having correct two parameters: 10 points (The student code has the correct two parameters in square_root() function.)
Looping against the difference in guesses: 10 points (The student code loops correctly against the difference in guesses.)
Calculating each next guess: 5 points (The student code calculates the next guess correctly.)
Returning the best guess: 5 points (The student code returns the best guess correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format.
3 points off for not providing the required output message format.
Total points: 94 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
-3, output messages don’t match the required message formats. See assignment for the required message format.
User
import sys
#get import for x
value_x = float(input("Enter x: "))
if value_x <=0:
print("x must be positive!")
sys.exit()
get import for tolerance
tolerance = float(input("Enter tolerance: "))
if tolerance <= 0:
print("tolerance must be positive!")
sys.exit()
#square root function
def square_root(value_x, tolerance):
current = value_x
better = (current + (value_x/current))/(2)
abs_number = better - current
abs_number_function = absolute_value(abs_number)
current = better
while abs_number_function > tolerance:
better = (current + (value_x/current))/(2)
abs_number = better - current
abs_number_function = absolute_value(abs_number)
current = better
return better
sq_root = square_root(value_x, tolerance)
print(f"Square root = {sq_root:.10f}")
Assistant
Grading based on the rubric:
Main function: 15 points
Getting and validating inputs: 5 points (The student code validates inputs correctly.)
Calling square_root() correctly: 5 points (The student code calls square_root() correctly with appropriate arguments.)
Printing results correctly: 5 points (The student code prints the result correctly to 5 decimal places as required.)
absolute_value() function: 5 points (The student code defines a correct absolute_value() function.)
square_root() function: 30 points
Having correct two parameters: 10 points (The student code has the correct two parameters in square_root() function.)
Looping against the difference in guesses: 10 points (The student code loops correctly against the difference in guesses.)
Calculating each next guess: 5 points (The student code calculates the next guess correctly.)
Returning the best guess: 5 points (The student code returns the best guess correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format.
3 points off for not providing the required output message format.
Total points: 94 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
-3, output messages don’t match the required message formats. See assignment for the required message format.
User
import sys
#defining absolute value function
def absolute_value (number):
if number >= 0:
abs_val = number
else:
abs_val = number * -1
return abs_val
#defining square root function
def square_root(x, tolerance):
x = x
guess = x
better_guess = (guess + (x/guess))/2
difference = absolute_value(better_guess - guess)
while difference > tolerance:
guess = better_guess
better_guess = (guess + (x/guess))/2
difference = absolute_value(better_guess - guess)
return better_guess
#prompt user for x and tolerance + check input
x = float(input("Enter x: "))
if x <= 0:
print("x must be positive!")
sys.exit()
tolerance = float(input("Enter tolerance: "))
if tolerance <= 0:
print("tolerance must be positive!")
sys.exit()
Getting and validating inputs: 5 points (The student code validates inputs correctly.)
Calling square_root() correctly: 5 points (The student code calls square_root() correctly with appropriate arguments.)
Printing results correctly: 5 points (The student code prints the result correctly to 5 decimal places as required.)
absolute_value() function: 5 points (The student code defines a correct absolute_value() function.)
square_root() function: 30 points
Having correct two parameters: 10 points (The student code has the correct two parameters in square_root() function.)
Looping against the difference in guesses: 10 points (The student code loops correctly against the difference in guesses.)
Calculating each next guess: 5 points (The student code calculates the next guess correctly.)
Returning the best guess: 5 points (The student code returns the best guess correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format.
3 points off for not providing the required output message format.
Total points: 94 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
-3, output messages don’t match the required message formats. See assignment for the required message format.
User
import sys
def absolute_value(x):
if x < 0:
return -x
else:
return x
return x
def square_root(x, tolerance):
current = x
better = (current + x/current)/2
difference = absolute_value(better - current)
while difference > tolerance:
better = (current + x/current)/2
difference = absolute_value(better - current)
current = better
return better
x = float(input("Enter x: "))
if x <= 0:
print("x must be positive!")
sys.exit()
else:
tolerance = float(input("Enter tolerance: "))
if tolerance <= 0:
print("tolerance must be postive!")
sys.exit()
Getting and validating inputs: 5 points (The student code validates inputs correctly.)
Calling square_root() correctly: 5 points (The student code calls square_root() correctly with appropriate arguments.)
Printing results correctly: 5 points (The student code prints the result correctly to 5 decimal places as required.)
absolute_value() function: 5 points (The student code defines a correct absolute_value() function.)
square_root() function: 30 points
Having correct two parameters: 10 points (The student code has the correct two parameters in square_root() function.)
Looping against the difference in guesses: 10 points (The student code loops correctly against the difference in guesses.)
Calculating each next guess: 5 points (The student code calculates the next guess correctly.)
Returning the best guess: 5 points (The student code returns the best guess correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format.
3 points off for not providing the required output message format.
Total points: 94 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
-3, output messages don’t match the required message formats. See assignment for the required message format.
User
You are an adept, highly detail oriented grading assistant. Given the instructor code and rubric grade the student code. Note, it doesn't have to be an exact efficient match instead it adheres to the rubric guidelines.
Rubric:
"""
General point breakdown
Main function: 15 points
Looping against the difference in guesses: 10 points
Calculating each next guess: 5 points
Returning the best guess: 5 points
Notes:
Do take off points for poor variable names. Random unrelated names should lose 5 points. Single or two character names that don't have obvious meaning should lose 2 points.
Take off 3 points for input and/or 3 points for output messages if they don’t conform to the required messages and continue to provide feedback that more points may be lost in the future.
Minor typos should typically result in 2 points off each.
My solution uses a function to get the user input. That's not required.
Note that students will lose 40 points if they use math.sqrt() or math.pow(). Another 10 points if they use abs() or math.abs().
Specific feedback
-3, user prompt message doesn’t match the required message format. See assignment for the required message format.
-3, output messages don’t match the required message formats. See assignment for the required message format.
-50, nothing submitted for this problem.
-40, can't use math.sqrt(), math.pow(), or any related built-in math functions.
-10, have to write your own absolute_value() function, can't use abs() or math.abs().
-5, the final estimate is supposed to be printed to 10 decimal places.
-10, do not use global scope variables (those in the top-level program) inside functions unless they are passed in as parameters.
-5, the loop in square_root() has to use the absolute_value() function to make sure the difference in estimates is positive.
-10, your loop in square_root() isn't right. You have to check if the difference between the two most recent estimates is greater than the tolerance and keep looping if so.
-10, you have to use two variables to track the current estimate and the better estimate each time through the loop so that you can stop the loop when the two estimates are close enough (less than the tolerance).
-5, have to return the current best estimate, not the previous best estimate.
-10, have to return the estimate at the end of the square_root() function, not print it out in the function.
Instructor Sample Code:
code
Assistant
Grading based on the rubric:
Main function: 15 points
Getting and validating inputs: 5 points (The student code validates inputs correctly.)
Calling square_root() correctly: 5 points (The student code calls square_root() correctly with appropriate arguments.)
Printing results correctly: 5 points (The student code prints the result correctly to 10 decimal places as required.)
absolute_value() function: 5 points (The student code defines a correct absolute_value() function.)
square_root() function: 30 points
Having correct two parameters: 10 points (The student code has the correct two parameters in square_root() function.)
Looping against the difference in guesses: 10 points (The student code loops correctly against the difference in guesses.)
Calculating each next guess: 5 points (The student code calculates the next guess correctly.)
Returning the best guess: 5 points (The student code returns the best guess correctly.)
Notes deductions:
0 points off for variable names.
Input/output message deductions:
3 points off for not using the required input message format.
3 points off for not providing the required output message format.
Total points: 94 out of 100
Specific feedback:
-3, user input message doesn’t match the required message format. See assignment for the required message format.
-3, output messages don’t match the required message formats. See assignment for the required message format.
User
You are an adept, highly detail oriented grading assistant. Given the instructor code and rubric grade the student code. Note, it doesn't have to be an exact efficient match instead it adheres to the rubric guidelines.
Rubric:
"""
General point breakdown
Main function: 15 points
Looping against the difference in guesses: 10 points
Calculating each next guess: 5 points
Returning the best guess: 5 points
Notes:
Do take off points for poor variable names. Random unrelated names should lose 5 points. Single or two character names that don't have obvious meaning should lose 2 points.
Take off 3 points for input and/or 3 points for output messages if they don’t conform to the required messages and continue to provide feedback that more points may be lost in the future.
Minor typos should typically result in 2 points off each.
My solution uses a function to get the user input. That's not required.
Note that students will lose 40 points if they use math.sqrt() or math.pow(). Another 10 points if they use abs() or math.abs().
Specific feedback
-3, user prompt message doesn’t match the required message format. See assignment for the required message format.
-3, output messages don’t match the required message formats. See assignment for the required message format.
-50, nothing submitted for this problem.
-40, can't use math.sqrt(), math.pow(), or any related built-in math functions.
-10, have to write your own absolute_value() function, can't use abs() or math.abs().
-5, the final estimate is supposed to be printed to 10 decimal places.
-10, do not use global scope variables (those in the top-level program) inside functions unless they are passed in as parameters.
-5, the loop in square_root() has to use the absolute_value() function to make sure the difference in estimates is positive.
-10, your loop in square_root() isn't right. You have to check if the difference between the two most recent estimates is greater than the tolerance and keep looping if so.
-10, you have to use two variables to track the current estimate and the better estimate each time through the loop so that you can stop the loop when the two estimates are close enough (less than the tolerance).
-5, have to return the current best estimate, not the previous best estimate.
-10, have to return the estimate at the end of the square_root() function, not print it out in the function.
import sys
#function that prints out
def print\_square(side\_length):
side = "\*" \* side\_length
print(side)
i = 2
spaces = "\*" + " " \* (side\_length - 2) + "\*"
while i < side\_length:
print(spaces)
i += 1
if side\_length == 1:
None
else:
print(side)
#ask for input
length = int(input("Enter side length: "))
#condition if input is bad
if length <= 0:
print("side length must be positive!")
sys.exit()
#insert input into function as its parameter and output
print\_square(length)
Student Code:
code
import sys
#Create the print\_square function
def print\_square(length):
for i in range(length):
#Print top and bottom rows with all \*
if i == 0 or i == length - 1:
print("\*" \* length)
#Print middle rows with blanks in the middle
else:
print("\*" + " " \* (length - 2) + "\*")
#Prompt user for side length
length = int(input("Enter side length: "))
#Make sure value is positive
if length <= 0:
print("side length must be positive!")
sys.exit()
print\_square(length)
Student Code:
code
import sys
def print\_square(length):
if length<=0:
print('Please a positive number!')
sys.exit()
for i in range(0,length):
if i == 0 or i == length-1:
line = '\*'\*length
print(line)
else:
line = '\*'+' '\*(length-2)+'\*'
print(line)
print\_square(5)
import sys
def get\_positive\_float(name):
float\_val = float(input(f"Enter {name}: "))
if float\_val <= 0:
print(f"{name} must be positive!")
sys.exit()
return float\_val
def absolute\_value(x):
if x < 0:
return -x
else:
return x
def square\_root(x, tolerance):
guess = x
next\_guess = (x/guess + guess)/2
while absolute\_value(guess-next\_guess) > tolerance:
guess = next\_guess
next\_guess = (x/guess + guess)/2
return next\_guess
x = get\_positive\_float("x")
tolerance = get\_positive\_float("tolerance")
root = square\_root(x, tolerance)
print(f"Square root = {root:.10f}")
Student Code:
code
import sys
def absolute\_value(x):
if x <0:
return -x
else:
return x
def square\_root(x, tolerance):
guess = x
better = (guess + x/guess) / 2
while absolute\_value(better-guess) > tolerance:
guess = better
better = (guess + x/guess) / 2
return better
x = float(input("Enter x: "))
if x <= 0:
print("x must be positive!")
sys.exit()
absolute\_value(x)
tolerance = float(input("Enter tolerance: "))
if tolerance <= 0:
print("tolerance must be positive!")
sys.exit()
square\_root(x,tolerance)
total = square\_root(x,tolerance)
print(f"Square root = {total:.10f}")
import sys
def get\_positive\_float(name):
float\_val = float(input(f"Enter {name}: "))
if float\_val <= 0:
print(f"{name} must be positive!")
sys.exit()
return float\_val
def absolute\_value(x):
if x < 0:
return -x
else:
return x
def square\_root(x, tolerance):
guess = x
next\_guess = (x/guess + guess)/2
while absolute\_value(guess-next\_guess) > tolerance:
guess = next\_guess
next\_guess = (x/guess + guess)/2
return next\_guess
x = get\_positive\_float("x")
tolerance = get\_positive\_float("tolerance")
root = square\_root(x, tolerance)
print(f"Square root = {root:.10f}")
Student Code:
code
#import sys module
import sys
# getting user input for x and tolerance values
x\_value = float(input("Enter x: "))
if x\_value <= 0:
print("x must be positive!")
sys.exit()
tolerance = float(input("Enter tolerance: "))
if tolerance <= 0:
print("tolerance must be positive!")
sys.exit()
# defining absolute value function
def absolute\_value(diff):
if diff < 0:
pos\_diff = diff \* (-1)
else:
pos\_diff = diff
return pos\_diff
# defining square root function
def square\_root(x\_value, tolerance):
pos\_diff = tolerance + 1
guess\_0 = x\_value ## (i.e. previous guess)
guess\_1 = x\_value ## (i.e. "better" guess)
while tolerance < pos\_diff:
#print(f"guess\_1 = {guess\_1} and guess\_0 = {guess\_0}")
numerator = guess\_1 + (x\_value/guess\_1)
#print(f"numerator = {numerator}")
guess\_1 = numerator / 2
#print(f"better = {guess\_1}")
diff = guess\_1 - guess\_0
#print(f"diff = {diff}")
pos\_diff = absolute\_value(diff)
#print(f"pos\_diff = {pos\_diff}")
guess\_0 = guess\_1
return guess\_1
# storing return value from square root function
babylonian\_sqrt = square\_root(x\_value, tolerance)
# printing output
print(f"Square root = {babylonian\_sqrt:.10f}")
import sys
def get\_positive\_float(name):
float\_val = float(input(f"Enter {name}: "))
if float\_val <= 0:
print(f"{name} must be positive!")
sys.exit()
return float\_val
def absolute\_value(x):
if x < 0:
return -x
else:
return x
def square\_root(x, tolerance):
guess = x
next\_guess = (x/guess + guess)/2
while absolute\_value(guess-next\_guess) > tolerance:
guess = next\_guess
next\_guess = (x/guess + guess)/2
return next\_guess
x = get\_positive\_float("x")
tolerance = get\_positive\_float("tolerance")
root = square\_root(x, tolerance)
print(f"Square root = {root:.10f}")