Day 013 - Project 13 : Grade Generator

If you have any questions, comments or issues with this project please post them here!

Built a grade calculator today! Definitely giving myself an A+ on this :sunglasses: !

https://replit.com/@JackAdem/Day-013-Project-13-Grade-Generator?v=1

Day 13 of #Replit100DaysOfCode #100DaysOfCode.

2 Likes

Hiya!
I cannot assign grade to the last line:
str(grade_in_percentage)+"% , " + "which is a grade " + grade )

Maybe def function I wrote wrong?

def grade(grade_in_percentage):


import time
print("This program will generate grade according percentage of exam.")
time.sleep(1)

print("")
name_of_exam= input("Please, type the name of exam subject: ")
time.sleep(1)

print("")
max_possible_score = int(input("Input the maximum possible score of the exam: "))
time.sleep(1)

print("")
your_score = int(input("Write your score of the exam: "))
time.sleep(1)

print("")
grade_in_percentage = round((your_score * 100)/max_possible_score,2)
print(grade_in_percentage)

def grade(grade_in_percentage):
  if grade_in_percentage >= 90: 
    return "A+"
  elif grade_in_percentage >= 80 and grade_in_percentage <= 89:
    return "A"
  elif grade_in_percentage >= 70 and grade_in_percentage <= 79:
    return "B"
  elif grade_in_percentage >= 60 and grade_in_percentage <= 69:
    return "C"
  elif grade_in_percentage >= 50 and grade_in_percentage <= 59:
    return "D"
  else:
    return "U"
              

print("Exam Grade generator")
time.sleep(1)
print("Name of the exam subject: " + name_of_exam)
time.sleep
print("Max. Possible score " + str(max_possible_score))
time.sleep(1)
print("Your score is: " + str(your_score))
time.sleep(1)
print("Your got " + str(grade_in_percentage)+"% , " + "which is a grade " + grade )

Good luck to all coders!

I got it right. But I’m gonna try to write it the same with function return and bisect.

import time
print("This program will generate grade according percentage of exam.")
time.sleep(1)

print("")
name_of_exam= input("Please, type the name of exam subject: ")
time.sleep(1)

print("")
max_possible_score = int(input("Input the maximum possible score of the exam: "))
time.sleep(1)

print("")
your_score = int(input("Write your score of the exam: "))
time.sleep(1)

print("")
grade_in_percentage = round((your_score * 100)/max_possible_score,1)
              

print("Exam Grade generator")
time.sleep(1)
print("Name of the exam subject: " + name_of_exam)
time.sleep (1)
print("Max. Possible score " + str(max_possible_score))
time.sleep(1)
print("Your score is: " + str(your_score))
time.sleep(1)
print("Your got " + str(grade_in_percentage)+"% , " + "which is a grade ")

if grade_in_percentage >= 90: 
  print("A")
elif grade_in_percentage >= 80 and grade_in_percentage <= 89:
  print("A-")
elif grade_in_percentage >= 70 and grade_in_percentage <= 79:
  print ("B")
elif grade_in_percentage >= 60 and grade_in_percentage <= 69:
  print ("C")
elif grade_in_percentage >= 50 and grade_in_percentage <= 59:
  print ("D")
else:
  print ("U")

Hi @interpio thanks for your posts. Functions (def) need the code underneath it to be indented e.g.

import time

def grade(grade_in_percentage):
    
    print("This program will generate grade according percentage of exam.")
    time.sleep(1)

I’d also recommend putting all the import lines at the top of your code.

Hope this helps!

Thanks. I’ve just started to learn how to create functions.

1 Like

I find it annoying, that I can not go back to previous days lessons to view the tutorial, when I am stuck. Is that somehow possible?
When doing the day 13 challenge, I am getting a syntax error in line 9 - the < sign, but I don´t know why? (I have never coded before, so sorry for the newbie question!) Can you help?

My code:

test=input("Name a test you recently did? ")
maxScore=int(input("What was the maximum score in the test? "))
score=int(input("What was your score in the test? "))
percentage=float(score/maxScore)*100
percentage=(round(percentage, 2))
print("Your score in percentage was: ", percentage, "%")
if percentage <50:
  print("Your grade is then U... bummer!")
elif percentage >=50 and <=59:
  print("Your grade is D")
elif percentage =>60 and <=69:
  print ("Your grade is C")
elif percentage =>70 and <=79:
  print("Your grade is B")
elif percentage =>80 and <=89:
  print("Your grade is A - great job!")
elif percentage =>90:
  print("You are a superstar! Your received and A+ for that one!")
else:
print("That seems wrong")

By the way, I have tried finding previous lessons via URL, but the URL for day 8 and 9 doesn´t follow logic??

All my prints are indented - don’t know why that doesn´t show up here, so that is not the mistake

It doesn’t show up here because you need to format your code. Put three backticks then py (```py) then start a new line and paste your code. Then do another three backticks. It should look something like this:

```py
# your code here
```

The line after else needs to be properly indented btw

Thank you - i will do that going forward

Yes, you are right - I have fixed it, but it still says invalid syntax with a red arrow pointed at the < in line 9?

Of course, you cannot do this

elif percentage >=50 and <=59:

But need this

elif percentage >=50 and percentage<=59:

You can use : elif 50 <= percentage <= 59: syntax if you don’t like repeating yourself :))

Also pay attention to identation. Python is very sensitive about that! Almoust as sensitive as my wife to my snoring …

1 Like

or
elif percentage in range(50, 60):

Ahhh… thank you! Ha, I feel your poor wife :smile:

Question:

Repl link:

print("Exam Grade Calculator")
nameOfExam = input("What is the name of your exam?")
print("The maximum possible score for this exam was 50.")
score = input("What score did you recieve in your", nameOfExam, "?")
percentage = (score/50)*100
if percentage => float("90"), round 
   print("Fab, you got an A+!")
else:
   print("Boo sucks to you:(")

There is an error in the if percentage part, but I forgot how to construct this part of the code. Can someone help me?

Hey @anannaislam, welcome to the community!

I’m not sure what happened on your if statement there. Maybe just replace , round with :?

And also you can just check if percentage >= 90, don’t need to cast that from a string to a float.

Feel free to message me and I can fix formative on posts like this :slight_smile:

1 Like