Create a program that will calculate a student’s grade in a class that uses a weighted gradebook.
A weighted system uses percentages to determine how much each assignment category is worth. For this project, use the following percentages:
Project Grades = 30% (weight = .30)
Participation Grades = 20% (weight = .20)
Quizzes = 10% (weight = .10)
Exams = 40% (weight = .40)
Grading scale:
A - 90-100
B - 80-89
C - 70-79
D - 60-69
F - Below 60
Note: You will multiply the average for each of the categories by its weight. The final grade is the sum of the calculated weights.
Can't get the code to the allow the user to enter grades in all 4 categories, because it gets stuck on the first category chosen and the loop just goes on and on without stopping asking for a list of scores. I attempted a loop inside a loop, but it only continued on the first one chosen as well. Need multiple grades entered into all 4 categories which is why I need the program to allow the user to enter grades to the other categories not just the one that is chosen first.
print ("Weighted Grade Calculator ")
name = input("Enter the Student's Name ")
number = input("Enter the Student's Number ")
x = input("Enter Assignment type: ")
c = 'y'
#Loop is in case user wants to calculate another students grade
while c=='y' or c=='Y':
if x >= "quiz" or x >= "Quiz":
input_string = input("Enter a list of scores separated by space ")
#Read ints separated by spaces
lst = input_string.split()
print("Calculating sum of element of input list")
#convert strings to ints and convert map to list
lst = list(map(int, lst))
#Find total and avg
total = sum(lst)
avg_1 = total/len(lst)
elif x >= "project" or x >= "Project":
input_string = input("Enter a list of scores separated by space ")
lst = input_string.split()
print("Calculating sum of element of input list")
lst = list(map(int, lst))
total = sum(lst)
avg_2 = total/len(lst)
elif x >= "participation" or x >= "Participation":
input_string = input("Enter a list of scores separated by space ")
lst = input_string.split()
lst = list(map(int, lst))
total = sum(lst)
avg_3 = total/len(lst)
elif x >= "exam" or x >= "Exam":
input_string = input("Enter a list of scores separated by space ")
lst = input_string.split()
print("Calculating sum of element of input list")
lst = list(map(int, lst))
total = sum(lst)
avg_4 = total/len(lst)
else:
print("error, please try again")
#Finds percentage earned from each category
w_quiz = avg_1 * 0.1
w_project = avg_2 * 0.3
w_participation = avg_3 * 0.2
w_exams = avg_4 * 0.4
total = w_project + w_quiz + w_participation + w_exams
if(total >= 90 and total <=100):
grade = 'A'
elif(total >= 80 and total < 90):
grade = 'B'
elif(total >= 70 and total < 80):
grade = 'C'
elif(total >= 60 and total < 70):
grade = 'D'
elif(total >= 0 and total < 60):
grade = 'F'
print ("Student Name: " + str(name))
print ("Student ID: " + str(number))
print ("Total Weighted Score: " + str(total) + "%")
print ("Letter Grade: " + grade)
c = input("Would you like to calculate another grade? (Y or N): ")
Not sure exactly what you are looking for, but this code will take as much input as you give it and at the end will calculate the average of all totals and its respective letter grade:
def calculate_letter(total):
#function calculates letter grade
if(total >= 90 and total <=100):
grade = 'A'
elif(total >= 80 and total < 90):
grade = 'B'
elif(total >= 70 and total < 80):
grade = 'C'
elif(total >= 60 and total < 70):
grade = 'D'
elif(total >= 0 and total < 60):
grade = 'F'
return grade
print ("Weighted Grade Calculator ")
name = input("Enter the Student's Name ")
number = input("Enter the Student's Number ")
totals = [] #initialize list to append scores to
while True:
project = float(input("Enter the percentage for Projects (numbers only): "))
participation = float(input("Enter the percentage for the Participation (numbers only): "))
quizzes = float(input("Enter the percentage for Quizzes (numbers only): "))
exams = float(input("Enter the percentage for the Final Exam (numbers only): "))
w_project = project * 0.3
w_participation = participation * 0.2
w_quiz = quizzes * 0.1
w_exams = exams * 0.4
total = w_project + w_quiz + w_participation + w_exams
grade = calculate_letter(total) #running the function defined above to evaluate letter grade from total
print ("Total Weighted Score: " + str(total) + "%")
print ("Letter Grade: " + grade)
c = input("Would you like to calculate another grade? (Y or N): ").lower()
totals.append(total)
if c == 'y':
#restarts the loop
continue
else:
#exits the loop
break
print(totals)
final_averaged_score = sum(totals) / len(totals) #finding the average of the list
final_grade = calculate_letter(final_averaged_score)
print ("Student Name: " + str(name))
print ("Student ID: " + str(number))
print ("Final Averaged score: " + str(final_averaged_score))
print ("Final letter grade: " + str(final_grade))
Related
I am creating a program that takes users and stores them in list and takes their marks and afterwards it grades them. I've done the user input part and the marks as well along with the average of them but I am struggling to give them grade and print it along with their name so it will be like Name marks Grade. If anyone can help me with this I'll be thankful greatly here is my code
students=[]
for i in range (2):
x=(input("Enter Student Name. \n"))
students.insert(i,x)
i+=1
print(students)
grades = []
for student in students:
grade = eval(input(f"Enter the grade for {student}: "))
grades.append(grade)
result = list(zip(students, grades))
print(result)
average = sum(grades) / len(grades)
print ( "Average is: " + str(average))
total = sum(grades)
# print ("Total is: " + str(total))
print("Highest marks", max(list(zip(grades, students))))
print("Lowest marks", min(list(zip(grades, students))))
## To do assign grades to each according to their marks
I am struggling to give them grade and print it along with their name so it will be like Name marks Grade.
Look at the below - it uses zip and loop
names = ['Jack','Dan']
grades = [67,86]
def _get_grade(grade):
if grade < 50:
return 'C'
elif grade >= 50 and grade <= 75:
return 'B'
else:
return 'A'
for name,grade in zip(names,grades):
print(f'Name: {name} - Grade: {_get_grade(grade)}')
I want to make a loop where I can input numbers, and then the loop will give me the average of the numbers that I inputted. But a problem that I am facing is that I do not know how to make the loop remember the previous numbers that I inputted. I want the loop to end if I put -1.
x = (input ("enter a number: "))
while x != "-1":
y = int(input("enter another number: " ))
total = 0 + y
if total <= 0:
totally = total
print (totally)
you may use a list to store all your numbers, when you finish the input you can compute the average:
nums = []
i = int(input("enter another number: " ))
while i != -1:
nums.append(i)
i = int(input("enter another number: " ))
avg = sum(nums) / len(nums)
print(avg)
if you like one-line solution:
from statistics import mean
from itertools import takewhile, count
print(mean(takewhile(lambda x : x !=-1, (int(input()) for _ in count() ))))
if you want to print intermediary average:
nums = []
i = int(input("enter another number: " ))
while i != -1:
nums.append(i)
print(sum(nums) / len(nums))
i = int(input("enter another number: " ))
also, you could use 2 variables to hold the current sum and the total count:
i = int(input("enter another number: " ))
s = 0
c = 0
while i != -1:
c += 1
s += i
print(s / c)
i = int(input("enter another number: " ))
Probably you should define your total var before, something like this:
x = int(input ("enter a number: "))
total = x
numLoops = 1
y = 0
while y != -1:
y = int(input("enter another number: " ))
total += y # This will store the summation of y's in total var
numLoops += 1
print(f"The average is: {total/numLoops}") # Prints the average of your nums
You can do the following:
values = []
while True:
x = int(input ("enter a number: "))
if x == -1:
break
else:
values.append(x)
print(sum(values)/len(values))
I try to calculate several properties of students:
the amount of students
the sum of the marks of the students
the lowest, the average and the highest mark they received.
Yet, the variable mark only shows 0.
How can I solve this problem using function but not max() and min()?
mark = 0
a = 0
student = 0
a = int(input("Enter Marks :"))
def maxx():
maxx = 0
for i in range(1, a):
if a> maxx :
maxx = a
return maxx
def minn():
minn = 0
for i in range(1, a):
if a < minn :
minn = a
return minn
while (a >= 0):
mark = mark + a
student = student + 1
a = int(input("Enter Marks :"))
print("Exit")
print("Total students :", student)
print ("The total marks is:", mark)
average = mark/student
print ("The average marks is:", average)
print("The max marks is :", maxx())
print("The min marks is :", minn())
Your code has a lot of problems. One of them is
for i in range(1, a):
This part makes no sense if you want a min or max value. You need to iterate over a list of grades instead.
mark and student are also unnecessary considering they can be replaced by sum and len respectively.
The entire code seems to lack a proper structure. Here's an example implementation. If you are not allowed to use sum or len, you may bring your own mark and student method back, but try not to make a mess and keep it readable:
def maxx(grades):
if (not grades): # if empty, we let the caller know
return None
res = grades[0] # we know the list is not empty
for i in grades:
if i > res:
res = i
return res
def minn(grades):
if (not grades):
return None
res = grades[0]
for i in grades:
if i < res:
res = i
return res
def main():
grades = [] # list of grades
while (True):
grade = int(input("Enter Mark: "))
if (grade < 0): break
grades.append(grade)
student_cnt = len(grades)
total = sum(grades)
print("Exit")
print("Total students :", student_cnt)
print("The total marks is:", total)
print ("The average marks is:", total / student_cnt)
print("The max marks is :", maxx(grades))
print("The min marks is :", minn(grades))
if __name__ == "__main__":
main()
Input/Output:
Enter Mark: 30
Enter Mark: 20
Enter Mark: 10
Enter Mark: 40
Enter Mark: -1
Exit
Total students : 4
The total marks is: 100
The average marks is: 25.0
The max marks is : 40
The min marks is : 10
For example, the molecular weight of water (H20) is: 2(1.00794) + 15.9994 = 18
Code:
formula = int(input("Enter the number of elements: "))
for i in range(formula):
element = input("enter your element: ")
molCount = float(input("enter the molecule count: "))
print(molCount)
atomWeight = float(input("enter the atomic weight: "))
print(atomWeight)
total = molCount*atomWeight
print(total)
total = total + total
print(total)
Need help on getting multiple elements added together...
There's a mistake on the line:
total = molCount*atomWeight
You probably meant total += molCount*atomWeight instead.
Firstly, define total before your for loop. Secondly, I think your equation needs to be
total += (molCount * atomWeight)
instead of the original. Edited code:
formula = int(input("Enter the number of elements: "))
total = 0
for i in range(formula):
molCount = int(input("Enter the molecule count: "))
print("Molecule count: " + str(molCount))
atomWeight = float(input("Enter the atomic weight: "))
print("Atomic Weight: " + str(atomWeight))
total += (molCount * atomWeight)
print(total)
I'm writing a python program that drops the lowest of four test scores. The program first prompts the user to enter their first four test scores, then the program should drop the lowest test score and take the average of the remaining three test scores. The program should then print the final letter grade. This is what I have so far and I keep receiving an error when dropping the lowest score.
#Enter four test scores as percentages (%)
test1 = int(input("Enter grade 1: 90"))
test2 = int(input("Enter grade 2: 80"))
test3 = int(input("Enter grade 2: 70)")
test4 = int(input("Enter grade 2: 80)")
#Drop lowest test score
print("The average, with the lowest score dropped" )
total =(test1 + test2 + test3)
#Calculate average
def calc_average(total):
return total /3
#Grade scale
def determine_score(grade):
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >=70:
grade = "C"
elif score >= 60:
grade = "D"
else:
grade = "F"
#Calculate final letter grade
print("The final grade is")
main()
I tried to write a program with the things that I understood from you.
Here is the explanation:
Taking four grades from user.
Dropping the lowest one.
Taking average.
Giving a letter grade according to the average.
Here is the code:
test1 = int(input("Enter grade 1: "))
test2 = int(input("Enter grade 2: "))
test3 = int(input("Enter grade 3: "))
test4 = int(input("Enter grade 4: "))
x = min(test1,test2,test3,test4)
total = float(test1 + test2 + test3 + test4 - x)
avg = total / 3
print("Your average is " + str(avg))
def determine_letter(grade):
letter =""
if grade >= 90:
letter = "A"
elif grade >= 80:
letter = "B"
elif grade >= 70:
letter = "C"
elif grade >= 60:
letter = "D"
else:
letter = "F"
print("The final letter grade is " + letter)
determine_letter(avg)