Making a Weighted Grading Scale in Python - python

Create a program that will calculate a student’s grade in a class that uses a weighted grade scale.
I have to be able to manually enter each Quiz, Test, Participation, and Project Grade. It's my first year learning Python at all, and it is my first language! Thanks for the help!
Edit: Right now the code is giving me this:
"
John Doe
John Doe , You made a function letter_grade at 0x7f4424330dd0"
name="John Doe"
print(name)
#Entering Particiaption Grade and Weight
def Participation(Participation1):
Participation1= int(input())
participation_average=int(input(Participation1/1))
return participation_average
def ParticipationW(ParticipationWeight):
ParticipationWeight = int(input())
return ParticipationWeight
#Entering Quiz Grades and Weight
def Quiz(Quiz1, Quiz2, Quiz3, Quiz4, Quiz5, Quiz6):
Quiz1 = int(input())
Quiz2 = int(input())
Quiz3 = int(input())
Quiz4 = int(input())
Quiz5 = int(input())
Quiz6 = int(input())
quiz_average=int(input((Quiz1+Quiz2+Quiz3+Quiz4+Quiz5+Quiz6)/6))
return quiz_average
def QuizW(QuizWeight):
QuizWeight = int(input())
return QuizWeight
#Projects
def Project(Project1, Project2, Project3, Project4, Project5, Project6):
Project1 = int(input())
Project2 = int(input())
Project3 = int(input())
Project4 = int(input())
Project5 = int(input())
Project6 = int(input())
project_average=int(input((Project1+Project2+Project3+Project4+Project5+Project6)/6))
return project_average
def ProjectW(ProjectWeight):
ProjectWeight = int(input())
return ProjectWeight
#Enter Test Grades and Variables
def Test(Test1, Test2, Test3, Test4):
Test1 = int(input())
Test2 = int(input())
Test3 = int(input())
Test4 = int(input())
test_average=int(input((Test1+Test2+Test3+Test4)/4))
return test_average
def TestW(TestWeight):
TestWeight = int(input())
return TestWeight
def letter_grade(FinalGrade):
FinalGrade=int(input((Participation * ParticipationW) + (Quiz * QuizW) + (Project * ProjectW) + (Test* TestW)))
if FinalGrade >= 90:
return "You made a A!"
elif FinalGrade >= 80:
return "You made a B!"
elif FinalGrade >= 70:
return "You made a C!"
elif FinalGrade >= 60:
return "You made a D!"
else:
return "Sorry, you failed."
print(name, ", You made a", letter_grade, ".")
This is what he has given us so far:
Enter Student Name:
Please enter the total possible quiz grade:60
Please enter quiz weight in decimal form:.15
Please enter the first quiz grade:10
Please enter the second quiz grade:5
Please enter the third quiz grade:6
Please enter the fourth quiz grade:7
Please enter the fifth quiz grade:10
Please enter the sixth quiz grade:9
Please enter the total possible Participation grade:100
Please enter participation weight in decimal form:.05
Please enter the Participation grade:100
Please enter the total possible project grade:600
Please enter project weight in decimal form:.50
Please enter the first project grade:100
Please enter the second project grade:100
Please enter the third project grade:90
Please enter the fourth project grade:80
Please enter the fifth project grade:80
Please enter the sixth project grade:50
Please enter the total possible test grade:400
Please enter test weight in decimal form:.30
Please enter the first test grade:100
Please enter the second test grade:90
Please enter the third test grade:80
Please enter the fourth test grade:50
Jon Doe's grades are:
Overall Quiz Grade: 11.75
Overall Participation Grade: 5.0
Overall Project Grade: 41.66666666666667
Overall Test Grade: 24.0
Final Grade: 82.41666666666667
Your Grade: B

Here is your answer dear all the best and welcome to Python
Code
name=input("Enter your name:")
def grade():
#Entering Particiaption Grade and Weight
Participation1= int(input("Entering Particiaption Grade :"))
participation_average=Participation1
ParticipationWeight = int(input("Entering Particiaption Weight:"))
#Entering Quiz Grades and Weight
Quiz1 = int(input("Enter Quiz 1 Grades:"))
Quiz2 = int(input("Enter Quiz 2 Grades:"))
Quiz3 = int(input("Enter Quiz 3 Grades:"))
Quiz4 = int(input("Enter Quiz 4 Grades:"))
Quiz5 = int(input("Enter Quiz 5 Grades:"))
Quiz6 = int(input("Enter Quiz 6 Grades:"))
quiz_average=(Quiz1+Quiz2+Quiz3+Quiz4+Quiz5+Quiz6)/6
QuizWeight = int(input("Enter Quiz weight:"))
#Projects
Project1 = int(input("Enter Project 1 Grades:"))
Project2 = int(input("Enter Project 2 Grades:"))
Project3 = int(input("Enter Project 3 Grades:"))
Project4 = int(input("Enter Project 4 Grades:"))
Project5 = int(input("Enter Project 5 Grades:"))
Project6 = int(input("Enter Project 6 Grades:"))
project_average=(Project1+Project2+Project3+Project4+Project5+Project6)/6
ProjectWeight = int(input("Enter Project Weight:"))
#Enter Test Grades and Variables
Test1 = int(input("Enter Test 1 Grades:"))
Test2 = int(input("Enter Test 2 Grades:"))
Test3 = int(input("Enter Test 3 Grades:"))
Test4 = int(input("Enter Test 4 Grades:"))
test_average=(Test1+Test2+Test3+Test4)/4
TestWeight = int(input("Enter Test Weight:"))
FinalGrade=(participation_average* ParticipationWeight) + (quiz_average* QuizWeight) + ( project_average * ProjectWeight) + (test_average* TestWeight)
print("Dear ",name,",")
if FinalGrade >= 90:
print("You made a A!")
elif FinalGrade >= 80:
print( "You made a B!")
elif FinalGrade >= 70:
print("You made a C!")
elif FinalGrade >= 60:
print("You made a D!")
else:
print("Sorry, you failed.")
grade()

Related

Python running calculations on many user inputs

I want my program to take any number of scores from any number of students, and run calculations on them.
student_number = 1
try:
score = int(input("Please enter Student " + str(student_number) + "'s score (-1: Exit): "))
except:
print("The score entered is not a number. Please enter it again.")
score = int(input("Please enter Student " + str(student_number) + "'s score (-1: Exit): "))
while score != -1:
try:
score = int(input("Please enter Student " + str(student_number) + "'s score (-1: Exit): "))
except:
print("The score entered is not a number. Please enter it again.")
score = int(input("Please enter Student " + str(student_number) + "'s score (-1: Exit): "))
more_student = input("Any more student? (Yes or No): ")
while more_student == "Yes":
student_number = student_number + 1
try:
score = int(input("Please enter Student " + str(student_number) + "'s score (-1: Exit): "))
except:
print("The score entered is not a number. Please enter it again.")
score = int(input("Please enter Student " + str(student_number) + "'s score (-1: Exit): "))
while score != -1:
score = int(input("Please enter Student " + str(student_number) + "'s score (-1: Exit): "))
more_student = input("Any more student? (Yes or No): ")
print("done")
Instead of print("done"), I want to somehow take every input I have received and be able to split it up by student, example output:
Student _ has 4 scores. Their average score is _.
Student _ has 3 scores. Their average score is _.
i'd use a dictionary i guess ? This will allow to collect data for each student, namely.
scores = {}
student = input("Student ? ") # Ask for student
if(student not in scores.keys()): # Create new student if necessary
scores[student] = []
score = int(input("Score ? ")) # Generate & store score for the student
scores[student].append(score)
Then to compute for each student the mean of the scores ... So many possibilities. The easiest one to me:
for student, score_list in scores.items():
nb_scores = len(score_list)
mean_score = sum(score_list)/len(score_list)
print("Student {} had {} scores, with a mean of {}". format(student, nb_scores, mean_score))
I'd just finished typing this up for another question of yours that got deleted -- it looks like the same basic problem as this one.
The approach in a nutshell (as I see the accepted answer to this version of the question is already doing) is to use two nested loops, breaking them when it's time to go to the outer loop.
scores = []
while True:
scores.append([])
while True:
try:
score = int(input(
f"Please enter Student {len(scores)}'s score (-1: Exit): "
))
if score == -1:
break
scores[-1].append(score)
except ValueError:
print("The score entered is not a number. Please enter it again.")
if input("Any more student? (Yes or No): ").lower() != "yes":
break
print(scores)
Please enter Student 1's score (-1: Exit): 78
Please enter Student 1's score (-1: Exit): 34
Please enter Student 1's score (-1: Exit): -1
Any more student? (Yes or No): yes
Please enter Student 2's score (-1: Exit): 45
Please enter Student 2's score (-1: Exit): -1
Any more student? (Yes or No): No
[[78, 34], [45]]
I included two infinite loops that breaks when -1 is entered. A hashmap is used where every Student ID is a key and is initialized with an empty array that stores the marks as the second loop executes itself.
marks = {}
while True:
i = int(input("Enter Student ID or press -1 to exit"))
if i == -1:
break
else:
marks[i] = []
while True:
x = int(input("Enter Mark or press -1 to exit"))
if x!=-1:
marks[i].append(x)
else:
break
for i in marks.keys():
count = len(marks[i])
avg = sum(marks[i])/count
print("Student {} has {} scores. Their average is {}".format(i, count, avg))

if and else in Python,if age is true grade is false,this program print is wrong

age = float(raw_input("Enter your age: "))
grade = int(raw_input("Enter your grade: "))
if age >= 8:
if grade >= 3:
print "You can play this game."
else:
print "Sorry, you can't play the game."
if age is true and grade is false,this program prints wrong output.but if age is false, it prints correct output.
Why is it happening?
You are leaving open the possibility that age >= 8 but grade < 3 in which you have no control flow to handle. You can correct this succinctly with an and statement
age = float(raw_input("Enter your age: "))
grade = int(raw_input("Enter your grade: "))
if age >= 8 and grade >= 3:
print "You can play this game."
else:
print "Sorry, you can't play the game."
age = float(raw_input("Enter your age: "))
grade = int(raw_input("Enter your grade: "))
if age >= 8:
if grade >= 3:
print"You can play this game."
else:
print"Sorry , you can't play the game."
else:
print "Sorry , you can't play the game."
You have to include an 'else' condition in your nested if/else statement:
age = float(raw_input("Enter your age: "))
grade = int(raw_input("Enter your grade: "))
if age >= 8:
if grade >= 3:
print "You can play this game."
else:
print"Sorry, you can't play this game."
else:
print "Sorry, you can't play this game."

Python - expected an indented block [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Just a beginner at Python trying to make a GPA calculator as a basic project, but getting an error in syntax: "expected an indented block"
import keyword
classes = int(input("How many classes do you need to calculate?: "))
gpa = 0.0
if classes == 1:
credits = int(input("Please enter the amount of credit hours of the class: "))
grade = input("What was the grade you have earned?: ")
letter_points = letterGradeConversion()
print(letter_points)
elif classes == 2:
credits = int(input("Please enter the amount of credit hours of the first class: "))
grade = input("What was the grade you have earned?: ")
credits = int(input("Please enter the amount of credit hours of the second class: "))
grade = input("What was the grade you have earned?: ")
elif classes == 3:
credits = int(input("Please enter the amount of credit hours of the first class: "))
grade = input("What was the grade you have earned?: ")
credits = int(input("Please enter the amount of credit hours of the second class: "))
grade = input("What was the grade you have earned?: ")
credits = int(input("Please enter the amount of credit hours of the third class: "))
grade = input("What was the grade you have earned?: ")
elif classes == 4:
credits = int(input("Please enter the amount of credit hours of the first class: "))
grade = input("What was the grade you have earned?: ")
credits = int(input("Please enter the amount of credit hours of the second class: "))
grade = input("What was the grade you have earned?: ")
credits = int(input("Please enter the amount of credit hours of the third class: "))
grade = input("What was the grade you have earned?: ")
credits = int(input("Please enter the amount of credit hours of the fourth class: "))
grade = input("What was the grade you have earned?: ")
else:
print("The max number of classes on this application is currently 4")
def letterGradeConversion():
if grade == A:
gpa = gpa + 4
elif grade == B:
gpa = gpa + 3
elif grade == C:
gpa = gpa + 2
elif grade == D:
gpa = gpa + 1
elif grade == F:
gpa = gpa + 0
else:
print("That is not a valid letter grade")
Not in code:
iuashd;alksdjas;kjdha;slkjaskljsakdljas;ljlkjf;lkjsFLKAJSD;KJASD;KLk;jaS'LKDJ;ldjk;'DH'AHKL'ASJKLASJKQIOWJWQOIH
Your function definition (everything after def ... :) has to be indented.
So
def letterGradeConversion():
if grade == A:
gpa = gpa + 4
...
instead of
def letterGradeConversion():
if grade == A:
gpa = gpa + 4
...
The entire block function definition for letterGradeConversion needs to be indented. Take a look at Python docs on indentation - https://docs.python.org/2.3/ref/indentation.html

Trying to increase a high score by user input in python

I'm working on a homework assignment for my game dev. class and I can't quite figure out what I'm doing wrong. I am trying to add numbers to a high score that has already been hardwired in by the use of user input. For example; Trying to add 100 points to Roger who currently has 3456 points. I just haven't quite figured out what I'm doing wrong to get the code to work. All and any help is very appreciated. Thank you.
str1 = ["Roger", 3456]
str2 = ["Justin", 2320]
str3 = ["Beth", 1422]
enter = 0
start = 0
Roger = ()
def incdec(sco):
return addit
def addition(num1):
return num1 + num1
def square(num):
print("I'm in square")
return num * num
def display(message):
"""Display game instuctions"""
print(message)
def instructions():
"""Display game instuctions"""
print("Welcome to the world's greatest game")
def main():
instructions()
scores = [str1, str2, str3]
start = input("Would you like to view the high score options? y/n ")
if start == "y":
print("""\
Hello! Welcome to the high scores!
Here are the current high score leaders!:
""")
print(scores)
print("""\n\
0 - Sort high scores
1 - Add high score
2 - Reverse the order
3 - Remove a score
4 - Square a number
5 - Add 2 numbers together
6 - Add to a score
7 - Subtract from a score
""")
option = int(input("Please enter your selection "))
while option < 8:
print(scores)
if option == 0:
scores.sort()
print("These are the scores sorted alphabetically")
print(scores)
option = option = int(input("Please enter your selection"))
elif option == 1:
print(scores)
print("Please enter your name and score; After entering your name, hit the return key and enter your score")
name = input()
score = int(input())
entry = (name,score)
scores.append(entry)
print(scores)
option = option = int(input("Please enter your selection"))
elif option == 2:
print(scores)
scores.reverse()
print("\nHere are the scores reversed")
print(scores)
option = option = int(input("Please enter your selection"))
elif option == 3:
print(scores)
print("Please enter the high score you would like to remove. After typing the name, hit the return key and enter the score")
name1 = input()
score1 = int(input())
remove = (name1,score1)
scores.remove(remove)
print(scores)
option = option = int(input("Please enter your selection"))
elif option == 4:
val = int(input("Give me a number to square"))
sqd = square(val)
print(sqd)
option = option = int(input("Please enter your selection"))
elif option == 5:
val0 = int(input("Give me one number"))
val1 = int(input("Give me another number"))
addi = (val0 + val1)
print(addi)
option = option = int(input("Please enter your selection"))
elif option == 6:
sc0 = input("Please enter the person whose score you would like to add to ")
sc1 = int(input("Please enter the amount you would like to add to their score "))
addit =(sc0 + str(sc1))
print(addit)
option = option = int(input("Please enter your selection"))
elif option == 7:
break
main()
You're adding a number to a string. What you need to do is search for the player in your scores list and then add the given number to their current score. Using your current structure, you could do the following:
def update_score(scores, person, amount):
# Loop through the current scores
for score in scores:
# Find the person we're looking for
if score[0].lower() == person.lower():
# Update their score
score[1] += amount
return scores
And then modify as such:
...
elif option == 6:
sc0 = input("Please enter the person whose score you would like to add to ")
sc1 = int(input("Please enter the amount you would like to add to their score "))
scores = update_score(scores, sc0, sc1)
print(scores)
option = option = int(input("Please enter your selection"))
...
Which produced for me:
Please enter the person whose score you would like to add to roger
Please enter the amount you would like to add to their score 100
[['Roger', 3556], ['Justin', 2320], ['Beth', 1422]]
However, I would refactor a lot of the boilerplate away and use dictionary lookups for tracking players. But the above solution solves your stated problem.

Loop Python Script

Im new to python and I am currently working on a python script and want to add a loop at the end of it, currently the code is as follows:
#FinalGrade
print ("\n")
Institution = str(input("Please Enter the Name of Your insitution: "))
print ("\n")
Year = str(input("Please Enter the Year of the Student (For Example, 'Year 2'): "))
print ("\n")
Student = str(input("Student Full Name: "))
print ("\n")
Grade1 = int(input("Enter Student's First Term Grade: "))
Grade2 = int(input("Enter Student's Second Term Grade: "))
Grade3 = int(input("Enter Student's Third Term Grade: "))
Grade4 = int(input("Enter Student's Fourth Term Grade: "))
average = (Grade1+Grade2+Grade3+Grade4)/4
print ("\n")
print ("Total Grade Average: %G" % (average))
passed_or_failed = "PASSED"
if average < 40:
passed_or_failed = 'FAILED'
print ("\n")
print ("%s has: %s" % (Student, passed_or_failed))
Id like to find out if it would be possible to set a loop so another student can be entered, would this be possible?
Thank you
Why not put it in an infinite loop?
cont = 'y'
while cont=='y':
print ("\n")
Institution = str(input("Please Enter the Name of Your insitution: "))
print ("\n")
Year = str(input("Please Enter the Year of the Student (For Example, 'Year 2'): "))
print ("\n")
Student = str(input("Student Full Name: "))
print ("\n")
Grade1 = int(input("Enter Student's First Term Grade: "))
Grade2 = int(input("Enter Student's Second Term Grade: "))
Grade3 = int(input("Enter Student's Third Term Grade: "))
Grade4 = int(input("Enter Student's Fourth Term Grade: "))
average = (Grade1+Grade2+Grade3+Grade4)/4
...
cont = input('Do you want to keep entering students? y/n: ')
Or if you want to keep all of the results:
results = []
cont = 'y'
while cont=='y':
print ("\n")
Institution = str(input("Please Enter the Name of Your insitution: "))
...
passed_or_failed = "PASSED"
if average < 40:
passed_or_failed = 'FAILED'
results.append(passed_or_failed)
...
cont = input('Do you want to keep entering students? y/n: ')
And you can just loop through the results to see them.
You mean just one more student to be entered?
You can probably do that with a while or for loop. Something along these lines:
counter = 0
while (counter < 2):
your existing code
....
counter += 1

Categories