What's wrong with this Python code?
def scale_midterm_grades(grades: List[float], multiplier: float,
bonus: float) -> None:
"""Modify each grade in grades by multiplying it by
multiplier and then adding bonus. Cap grades at 100.
>>> grades = [45, 50, 55, 95]
>>> scale_midterm_grades(grades, 1, 10)
>>> grades
[55, 60, 65, 100]
"""
for grade in grades:
grade = grade*multiplier +
bonus
if grade > 100:
grade = 100
There are two mistakes in the above python program.
1)In python,You don't have to decare datatype of the variables. Python will take it directly based on the value you give as an input.
def scale_midterm_grades(grades: List[float], multiplier: float, bonus: float) -> None: must be replaced with def scale_midterm_grades(grades,multiplier,bonus):
2)While using lists, you can modify the values in the list using INDEXING ,we cannot directly modify the values.
for grade in grades:
grade = grade*multiplier +
bonus
if grade > 100:
grade =
100
The above code must be replaced with the following code:
for i in
range(0,len(grades)):
grades[i] =
grades[i]*multiplier + bonus
if grades[i] > 100:
grades[i] = 100
Modified Code
def scale_midterm_grades(grades,multiplier,bonus):
for i in range(0,len(grades)):
grades[i] =
grades[i]*multiplier + bonus
if grades[i] > 100:
grades[i] = 100
return grades
grades = [45, 50, 55, 95]
l=scale_midterm_grades(grades, 1, 10)
print(l)
OUTPUT
What's wrong with this Python code? def scale_midterm_grades(grades: List[float], multiplier: float, bonus: float) -> None: ...
### Question in python code, write the code on the following program: def minmaxgrades(grades, names): """ Computes the minimum and maximujm grades from grades and creates a list of two student names: first name is the student with minimum grade and second name is the student with the maximum grade. grades: list of non-negative integers names: list of strings Returns: list of two strings """ def main(): """ Test cases for minmaxgrades() function """ input1 = [80, 75, 90, 85,...
Python please help! Thanks you Write a code to get an unlimited number of grades from the user (the user can press enter to finish the grades input, or use a sentinel, for example-1), and then calculate the GPA of all the grades and displays the GPA To do this you might need some help. Try to follow the following process (and check your progress by printing different values to make sure they are as they supposed to be): 1-...
Having trouble with python! Write a program to build a list of grades, print them out, add to them and count occurrences, and find the amount of the 2-digit grade values. Here are the criteria a) Your program “L6QI initials.py" must start with a commented ID Box AND include a comment that indicates the e of the program. EACH of the five functions in your program must state its purpose in comments too The main function in your program must...
python 3.6 please ! and comment your code .def remove(val, xs, limit-None): Remove multiple copies of val from xs (directly modify the list value that xs refers to). You may only remove up to the first limit occurrences of val. If limit -3, and xs had ten copies of val in it, then you'd only remove the first three and leave the last seven in place. When limitNone, there's truly no limit (and we remove all occurrences of val). Return...
Cannot figure our what's wrong with this code but it won't stop running when I run it. This is python code for a pac-man game to find the corners of the maze def cornersHeuristic(state, problem): """ A heuristic for the CornersProblem that you defined. state: The current search state (a data structure you chose in your search problem) problem: The CornersProblem instance for this layout. This function should always return a number that is a lower bound on the shortest...
Java please 9:55 Note @13 simple lists of numbers. If the user selects option 2, your program should prompt for a list of integer grades (0 100, inclusive). When the list is entered print out the following statistics: total grades, the breakdown of grades by letter both count and percentage), the highest and lowest grades in the list, and the class average Example #1 Please enter a list of grades (0-100): 55 65 75 85 95-1 Total number of grades...
python 3 question Project Description Electronic gradebooks are used by instructors to store grades on individual assignments and to calculate students’ overall grades. Perhaps your instructor uses gradebook software to keep track of your grades. Some instructors like to calculate grades based on what is sometimes called a “total points” system. This is the simplest way to calculate grades. A student’s grade is the sum of the points earned on all assignments divided by the sum of the points available...
CAN SOMEONE PLEASE EXPLAN FO ME WHATS WRONG WITH MY CODE WHEN EVEN I RUN IT IT GIVE ME THIS MASSAGE IM USING python BTW Traceback (most recent call last): File "../resource/asnlib/public/RUN.py", line 20, in <module> exec(source_code, dict()) File "<string>", line 60, in <module> NameError: name 'total_rough_sod' is not defined ) from math import pi length = float(input('Enter Course Length:')) width = float(input('Enter Course Width:')) def calculate_smooth_sod(width): grean_area_raduis= (width/2)/2 total_smooth_sod=2*pi*(grean_area_raduis**2) return total_smooth_sod def calculate_sand_trap_area(width): sand_trap_radius=(width/3)/2 sand_trap_area=pi*(sand_trap_radius**2) return sand_trap_area def calculate_rough_sod(length,...
PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...
The Computer Science Instructor has just completed compiling all the grades for the C++ Programming class. The grades were downloaded into a file titled ‘studentGrades.txt’ (attached). Write a C++ Program that reads this file and calculates the following as described : The final semester numeric and letter grade (using 10 point scale) Calculated as follows: Labs 1-6 (worth 50% of final grade) Lab 7 is extra credit (worth 2 % of final grade OR replaces lowest lab grade – Select...