Search code examples
pythonvariablesvariable-assignmentletter

Assigning Letters To variable


This is the code i have made and whatever the score is the output is always "Grade: ", I want it to output a letter equevalent but it will not. I have tried using commas but nothing seems to work. I have tied looking around but cannot find a answer to my problem.

score = input
grade = ""

if score == "5":
    grade == "A"

if score == "4":
    grade == "B"

if score == "3":
    grade == "C"

if score == "2":
    grade == "D"

if score == "1":
    grade = "E"

if score == "0":
    grade == "F"

print("Grade:" + grade)

Solution

  • You need to :

    1- use one operator = to assign.

    2- Assign a value to score via input()

    score = input("enter the score (0-5):")
    grade = ""
    
    if score == "5":
        grade = "A"
    
    if score == "4":
        grade = "B"
    
    if score == "3":
        grade = "C"
    
    if score == "2":
        grade = "D"
    
    if score == "1":
        grade = "E"
    
    if score == "0":
        grade = "F"
    
    print("Grade:" + grade)