Below is a program that's meant to calculate a percentage and print a message telling them what grade they received based on what percentage of their score was. problem is every time I run it I get the message: TypeError: can only concatenate str (not "float") to str I'm incredibly new to python and would appreciate any help.
score = input("Please enter your score:")
percentage = float(score) / 50 * 100
print(percentage)
if float(score) <59.99:
print("you have passed with " percentage "%" " , and received a grade F")
elif float(score) >60 and float(score) <69.99:
print("you have passed with " percentage "%" " , and received a grade D")
elif float(score) >70 and float(score) <79.99:
print("you have passed with " percentage "%" " , and received a grade C")
elif float(score) >80 and float(score) <89.99:
print("you have passed with " percentage "%" " , and received a grade B")
elif float(score) >90 and float(score) <100:
print("you have passed with " percentage "%" " , and reveived a grade A")
elif float(score) <50:
print("Score is greater than 50.")
update: thanks for the help it's running perfectly now, code below is for reference
score = input("Please enter your score:")
percentage = float(score) / 50 * 100
print(percentage)
if float(score) < 30:
print("you have passed with ", percentage, "%", " , and received a grade F")
elif float(score) >=30 and float(score) <35:
print("you have passed with ", percentage, "%", " , and received a grade D")
elif float(score) >=35 and float(score) <40:
print("you have passed with ", percentage, "%", " , and received a grade C")
elif float(score) >=40 and float(score) <45:
print("you have passed with ", percentage, "%", " , and received a grade B")
elif float(score) >=45 and float(score) <=50:
print("you have passed with ", percentage, "%", " , and reveived a grade A")
elif float(score) >50:
print("Score is greater than 50.")
CodePudding user response:
Line 15
elif float(score) <50:
score is a string. So you need to do the same thing you did in line 2.
CodePudding user response:
Try this
# Python Program to Calculate Total Marks Percentage and Grade of a Student
print("Enter the marks of five subjects::")
subject_1 = float (input ())
subject_2 = float (input ())
subject_3 = float (input ())
subject_4 = float (input ())
subject_5 = float (input ())
total, average, percentage, grade = None, None, None, None
# It will calculate the Total, Average and Percentage
total = subject_1 subject_2 subject_3 subject_4 subject_5
average = total / 5.0
percentage = (total / 500.0) * 100
if average >= 90:
grade = 'A'
elif average >= 80 and average < 90:
grade = 'B'
elif average >= 70 and average < 80:
grade = 'C'
elif average >= 60 and average < 70:
grade = 'D'
else:
grade = 'E'
# It will produce the final output
print ("\nThe Total marks is: \t", total, "/ 500.00")
print ("\nThe Average marks is: \t", average)
print ("\nThe Percentage is: \t", percentage, "%")
print ("\nThe Grade is: \t", grade)