Donate SIGN UP

I Need Help Coding

Avatar Image
bob221443 | 17:31 Mon 27th May 2019 | Technology
12 Answers
I have a mostly finished grade calculator that needs help getting finished up and the syntax errors being worked out. It is written in python 3:



studentGradeMath = input("Enter student letter grade for Math - ").upper()
studentGradeWriting = input("Enter student letter grade for Writing - ").upper()
studentGradeReading = input("Enter student letter grade for Reading- ").upper()
studentGradeAttendance = input("Enter student letter grade for Attendance- ").upper()
studentGradeHistory = input("Enter student letter grade for History - ").upper()

if studentGradeMath == "A":
print("4")
elif studentGradeMath == "A-":
print("3.5")
elif studentGradeMath == "B":
print("3")
elif studentGradeMath == "B-":
print("2.5")
elif studentGradeMath == "C":
print("2")
elif studentGradeMath == "C-":
print("1.5")
elif studentGradeMath == "D":
print("1")
elif studentGradeMath == "D-":
print("0.5")
else studentGradeMath == "F":
print("0")

if studentGradeWriting == "A":
print("4")
elif studentGradeWriting == "A-":
print("3.5")
elif studentGradeWriting == "B":
print("3")
elif studentGradeWriting == "B-":
print("2.5")
elif studentGradeWriting == "C":
print("2")
elif studentGradeWriting == "C-":
print("1.5")
elif studentGradeWriting == "D":
print("1")
elif studentGradeWriting == "D-":
print("0.5")
else studentGradeWriting == "F":
print("0")

if studentGradeHistory == "A":
print("4")
elif studentGradeHistory == "A-":
print("3.5")
elif studentGradeHistory== "B":
print("3")
elif studentGradeHistory == "B-":
print("2.5")
elif studentGradeHistory == "C":
print("2")
elif studentGradeHistory == "C-":
print("1.5")
elif studentGradeHistory == "D":
print("1")
elif studentGradeHistory == "D-":
print("0.5")
else studentGradeHistory == "F":
print("0")

if studentGradeAttendance == "A":
print("4")
elif studentGradeAttendance == "A-":
print("3.5")
elif studentGradeAttendance == "B":
print("3")
elif studentGradeAttendance == "B-":
print("2.5")
elif studentGradeAttendance == "C":
print("2")
elif studentGradeAttendance == "C-":
print("1.5")
elif studentGradeAttendance == "D":
print("1")
elif studentGradeAttendance == "D-":
print("0.5")
else studentGradeAttendance == "F":
print("0")

if studentGradeReading == "A":
print("4")
elif studentGradeReading == "A-":
print("3.5")
elif studentGradeReading == "B":
print("3")
elif studentGradeReading == "B-":
print("2.5")
elif studentGradeReading == "C":
print("2")
elif studentGradeReading == "C-":
print("1.5")
elif studentGradeReading == "D":
print("1")
elif studentGradeReading == "D-":
print("0.5")
else studentGradeReading == "F":
print("0")
Gravatar

Answers

1 to 12 of 12rss feed

Avatar Image
if studentGradeMath == "A": print("4") elif studentGradeMath == "A-": print("3.5") elif studentGradeMath == "B": print("3") elif studentGradeMath == "B-": print("2.5") elif studentGradeMath == "C": print("2") elif studentGradeMath == "C-": print("1.5") elif studentGradeMath == "D": print("1") elif studentGradeMath == "D-": print("0.5")...
18:55 Mon 27th May 2019
Python was not a language I learnt, but give an example of the sytax error you are getting.
Question Author
Tuvok, this syntax error i have been getting has come up when it says else studentGradeMath == "F":
print("0")

i don t see any issue with the line, but something is there
if studentGradeMath == "A":
print("4")
elif studentGradeMath == "A-":
print("3.5")
elif studentGradeMath == "B":
print("3")
elif studentGradeMath == "B-":
print("2.5")
elif studentGradeMath == "C":
print("2")
elif studentGradeMath == "C-":
print("1.5")
elif studentGradeMath == "D":
print("1")
elif studentGradeMath == "D-":
print("0.5")
else:
print("0")

else statements don't have a conditional, and ensure the print statements are indented.
else?
Would the else statement have to be altered for the other ifs?
I’ll ask my son as he put the answer in. It’s all Dutch to me.
Although I am not familiar with Python3 the logic would suggest Rocky is correct.
'Else' means 'if none of the above conditions are met' and requires a command like 'print' rather than another condition. This applies to the last statement for each of the paragraphs (subjects).
you could cut it down by 90% if you used a look up table.
I also don't know Python but, as has been hinted, this hugely bloated code could be reduced and simplified greatly by using an array-type structure to store the look up keys and values. If I were writing this in C#, I'd be using a Dictionary generic control.
Question Author
Yes, it can be shortened, but i have been bored and i recently learn three new coding languages with nothing to do with them.
As other posters have said, Bob, we'd prefer a program which looks something (not that I speak Python) like:

print ("Your grade ", YourGrade, " gives you a score of", Scores[YourGrade])
Question Author
I fixed and finished it. thank you everyone. you can customize the calculator and other peices of it and add or remove as you see fit:

studentGradeMath = input("Enter student letter grade for Math - ").upper()
studentGradeWriting = input("Enter student letter grade for Writing - ").upper()
studentGradeReading = input("Enter student letter grade for Reading- ").upper()
studentGradeAttendance = input("Enter student letter grade for Attendance- ").upper()
studentGradeHistory = input("Enter student letter grade for History - ").upper()

if studentGradeMath == "A":
print("4")
elif studentGradeMath == "A-":
print("3.5")
elif studentGradeMath == "B":
print("3")
elif studentGradeMath == "B-":
print("2.5")
elif studentGradeMath == "C":
print("2")
elif studentGradeMath == "C-":
print("1.5")
elif studentGradeMath == "D":
print("1")
elif studentGradeMath == "D-":
print("0.5")
else:
print("0")

if studentGradeWriting == "A":
print("4")
elif studentGradeWriting == "A-":
print("3.5")
elif studentGradeWriting == "B":
print("3")
elif studentGradeWriting == "B-":
print("2.5")
elif studentGradeWriting == "C":
print("2")
elif studentGradeWriting == "C-":
print("1.5")
elif studentGradeWriting == "D":
print("1")
elif studentGradeWriting == "D-":
print("0.5")
else:
print("0")

if studentGradeHistory == "A":
print("4")
elif studentGradeHistory == "A-":
print("3.5")
elif studentGradeHistory== "B":
print("3")
elif studentGradeHistory == "B-":
print("2.5")
elif studentGradeHistory == "C":
print("2")
elif studentGradeHistory == "C-":
print("1.5")
elif studentGradeHistory == "D":
print("1")
elif studentGradeHistory == "D-":
print("0.5")
else:
print("0")

if studentGradeAttendance == "A":
print("4")
elif studentGradeAttendance == "A-":
print("3.5")
elif studentGradeAttendance == "B":
print("3")
elif studentGradeAttendance == "B-":
print("2.5")
elif studentGradeAttendance == "C":
print("2")
elif studentGradeAttendance == "C-":
print("1.5")
elif studentGradeAttendance == "D":
print("1")
elif studentGradeAttendance == "D-":
print("0.5")
else:
print("0")

if studentGradeReading == "A":
print("4")
elif studentGradeReading == "A-":
print("3.5")
elif studentGradeReading == "B":
print("3")
elif studentGradeReading == "B-":
print("2.5")
elif studentGradeReading == "C":
print("2")
elif studentGradeReading == "C-":
print("1.5")
elif studentGradeReading == "D":
print("1")
elif studentGradeReading == "D-":
print("0.5")
else:
print("0")





def add(x, y, g, f, t):
return x + y + g + f + t




print("Select operation.")
print("1.Add")


choice = input("Enter choice(1):")

num1 = int(input("Enter first number: "))
num2 = int(input("Enter next number: "))
num3 = int(input("Enter next number: "))
num4 = int(input("Enter next number: "))
num5 = int(input("Enter next number: "))

if choice == '1':
print(num1,"+",num2, "+",num3,"+",num4, "+",num5,"=", add(num1,num2,num3,num4,num5))

else:
print("Invalid input")

1 to 12 of 12rss feed

Do you know the answer?

I Need Help Coding

Answer Question >>