Mtoklitz113
Mtoklitz113

Reputation: 3878

The output is accepting the values I give and running without any errors, but print statement is not getting executed

I'm just getting started out with python and while practicing functions to print grade of a student whose name and score I input, it runs without any errors.

I just am not able to get it print the name and grades no matter what I do.

The code:

namee=input('What is your name: ')
scoree=float(input("What is your grade: "))
def markz(name,score):
    if score >= 9.0 and score <= 9.9: return "A"
    elif score >=8.0 and score <= 8.9: return "B"
    elif score >=7.0 and score <= 7.9: return "C"
    elif score >=6.0 and score <= 6.9: return "D"
    elif score <=5.0 : return "F"
    else: return "Invalid Grade"
    print("Hello ,"+name+". You are graded ",score)
markz(namee,scoree)

I want the output to be like, Hello, xyz. You are graded B

Upvotes: 0

Views: 34

Answers (1)

baduker
baduker

Reputation: 20042

Basically, you have to return markz() in the print statement. Also, I've simplified your code a bit.

Try this:

def markz(score):
    if 9.0 <= score <= 9.9:
        return "A"
    elif 8.0 <= score <= 8.9:
        return "B"
    elif 7.0 <= score <= 7.9:
        return "C"
    elif 6.0 <= score <= 6.9:
        return "D"
    elif score <= 5.0:
        return "F"
    else:
        return "Invalid Grade"


namee = input('What is your name: ')
scoree = float(input("What is your grade: "))

print("Hello , " + namee + ". You are graded ", markz(scoree))

Sample output:

What is your name: Foo
What is your grade: 8
Hello , Foo. You are graded  B

The reason it wasn't working for you was that the print("Hello ,"+name+". You are graded ",score) is simply unreachable. You've put it after the last return so it would never got executed.

Upvotes: 2

Related Questions