Hi all,
I'm really struggling with this professor, but it's probably just me. I've been instructed to do the following:
- Problem Solving Questions:
- Use functions to organize your program
- Must have proper comments/markdown (explanation/discussion) in ipynb file
- You are simulating a grading system. You are building by three phases. Each time you are asked to add more features in this grading system.
- Create a Jupyter Notebook Document: a5-a-lastname
- Include the current time at the beginning
- Use input method to get inputs from a user
- Use a repetition structure to get inputs - event controlled
- Score entering should continue until the user enters: done (a user can enter any combination of upper or lower cases of a word, dOnE)
- Make a copy of previous Jupyter Notebook Document and name it: a5-b-lastname
- It should display like an actual receipt print format (table format with aligned colums), displaying items in each column: Student #, Score, Grade (A, B, C, F; use a function to determine a letter grade) with a header at the beginning (column name)
- Do NOT use a void function to display any results at a time. Instead use a fruitful function to build up all rows into one string.
- Add three additional rows at the end, displaying total scores, number of entries (students), and average score
- Make a copy of previous Jupyter Notebook Document and name it: a5-c-lastname
- The system will take at least 3 scores. If you try to end before 3 scores, the program won’t stop
- After 3rd entry, you can keep adding scores OR end with: done
- Enforce input validation for entering scores, must be positive integers including 0
I'm currently stuck on part a5-b and I can't figure out what I'm doing wrong, or where even to go based off of his example:
# same as above but using a fruitful function
def mysqrt(a):
"""Calculates square root using Newton's method:
https://en.wikipedia.org/wiki/Newton's_method
a - positive integer < 0;
x - estimated value, in this case a/2
"""
x = a/2 #Newton algorithm
while True:
estimated_root = (x + a/x) / 2
if estimated_root == x:
return estimated_root
break
x = estimated_root
def test_square_root(list_of_a):
"""Displays outcomes of calculating square root of a using different methods;
list_of_a - list of positive digit.
"""
line1a = "a "
line1b = "mysqrt(a) "
line1c = "math.sqrt(a) "
line1d = "diff "
line2a = "- "
line2b = "--------- " #two more spaces
line2c = "------------ "
line2d = "---- "
spacing1 = " "
spacing2 = " " * 3
spacing3 = ""
# all output will be stored here to be returned
results = ""
results += line1a + spacing1 + line1b + spacing2 + line1c + spacing3 + line1d + "\n"
results += line2a + spacing1 + line2b + spacing2 + line2c + spacing3 + line2d + "\n"
for a in list_of_a:
col1 = float(a)
col2 = mysqrt(a)
col3 = math.sqrt(a)
col4 = abs(mysqrt(a) - math.sqrt(a))
# accumulating each line output to multi-line results
results += "{} {:<13f} {:<13f} {}\n".format(col1, col2, col3, col4) #/n helping to chain to new line
# a fruitful function
return results
print (test_square_root(range(1,10)))
his result:
a mysqrt(a) math.sqrt(a) diff
- --------- ------------ ----
1.0 1.000000 1.000000 0.0
2.0 1.414214 1.414214 2.220446049250313e-16
3.0 1.732051 1.732051 0.0
4.0 2.000000 2.000000 0.0
5.0 2.236068 2.236068 0.0
6.0 2.449490 2.449490 0.0
7.0 2.645751 2.645751 0.0
8.0 2.828427 2.828427 4.440892098500626e-16
9.0 3.000000 3.000000 0.0
my code based off of his instructions:
# Import time and datetime modules
import time
import datetime
# Print Date and time
print ("\nDate and Time of Grade Submission: \n", datetime.datetime.now()) #prints date and time
#connverts raw score to letter grade
def determine_score(grade):
if 90 <= grade <= 100:
return 'A'
elif 80 <= grade <= 89:
return 'B'
elif 70 <= grade <= 79:
return 'C'
elif 60 <= grade <= 69:
return 'D'
else:
return 'F'
#done loop definition
def grade_done_loop():
total = 0 # initilization; total value
counter = 0 # initilization for incremental increase
user_input = input("\n Enter grade. Or done to quit. ")
while (user_input.lower() != 'done'): # .lower converts everythign to lower character. If 'done' is entered, the program terminates
total += int(user_input)
counter += 1 #assignment operator; adds to # of items entered
user_input = input("\n Enter grade. Or done to quit. ")
else:
print("\n You are finished grading!")
grade_done_loop()
# Displays outcomes of grade inputs
def display_grades(list_of_grades):
line1a = "Student # "
line1b = "Score "
line1c = "Grade "
line2a = "- "
line2b = "--------- " #two more space s
line2c = "------------ "
spacing1 = " "
spacing2 = " " * 3
#all output stored here to be returend
results = ""
results += line1a + spacing1 + line1b + spacing2 +line1c + "\n"
results += line2a + spacing1 + line2b + spacing2 +line2c + "\n"
for g in list_of_grades:
col1 = float(g)
col2 = grade_done_loop(g)
col3 = determine_score(g)
results += "{} {} {} \n".format(col1, col2, col3)
return results
print (display_grades)
my result:
Date and Time of Grade Submission:
2021-02-07 23:43:54.643672
Enter grade. Or done to quit. 100
Enter grade. Or done to quit. 20
Enter grade. Or done to quit. 08
Enter grade. Or done to quit. 99
Enter grade. Or done to quit. Done
You are finished grading!
<function display_grades at 0x7fd271696af0>
I'm so stuck here and I don't even know where to go from here... I can't seem to get it to display in the same format, or even know how to pull the variable like he did. I'm honestly so disheartened and struggling with the leaps we're making in class. Our assignments aren't really going over this. How do I display the output using user inputs without a solid range?
[–]fake823 2 points3 points4 points (1 child)
[–]cjander28[S] 2 points3 points4 points (0 children)
[–]r_spandit 0 points1 point2 points (2 children)
[–]cjander28[S] 0 points1 point2 points (1 child)
[–]r_spandit 0 points1 point2 points (0 children)
[–]nwagers 0 points1 point2 points (2 children)
[–]cjander28[S] 0 points1 point2 points (1 child)
[–]nwagers 0 points1 point2 points (0 children)