-3

I'm still new to python. Please help me. I'm trying to get an output with calling function in a single line only but the output that is called from the function gets print first leaving the print stated as a None. What should I do? Thanks for the help in advance.

My code:

    def getGrade(mark):
        if mark>=80:
            print("A")
        elif mark>=60 and mark<=79:
            print("B")
        elif mark>=40 and mark<=59:
            print("C")
        elif mark>0 and mark<=39:
            print("F")
        else:
            print("Error")

    user={}
    for x in range(4):
    a=input("Please enter your name: ")
    b=int(input("Please enter your marks: "))
    user[a.title()]=b
    print(f"Hi {a}!Your Grade is {getGrade(b)}")
    print(user)

The output I got:

Please enter your name: izz

Please enter your marks: 99

A

Hi izz!Your Grade is None

Please enter your name: mark

Please enter your marks: 65

B

Hi mark!Your Grade is None

Please enter your name: Kevin

Please enter your marks: 33

F

Hi kevin!Your Grade is None

Please enter your name: felly

Please enter your marks: 55

C

Hi felly!Your Grade is None

{'Izz': 99, 'Mark': 65, 'Kevin': 33, 'Felly': 55}

This is how I suppose to print out the output: Example of output (from 1 student): Hi Adam. Your grade is B.

  • 3
    Welcome to Stack Overflow! Please avoid posting images (or worse, links to images) of code or errors. Anything text-based (code and errors) should be posted as text directly in the question itself and formatted properly as a [mre]. You can get more [formatting help here](https://stackoverflow.com/help/formatting). You can also read about [why you shouldn't post images/links of code](//meta.stackoverflow.com/q/285551). – Tomerikoo May 31 '22 at 13:01
  • 2
    You need the function to `return`, not `print`... – Tomerikoo May 31 '22 at 13:02
  • Please, include the code snippet in the question. – Chizaram Igolo May 31 '22 at 13:02
  • 2
    Does this answer your question? [Why is this printing 'None' in the output? (duplicate)](https://stackoverflow.com/q/28812851/6045800) – Tomerikoo May 31 '22 at 13:04
  • Why did you post your question to review if you didn't solve any of the issues with your question? Please don't waste reviewers time and [edit] your question properly. Anyway, it is a duplicate and you can find your answer in other existing questions – Tomerikoo May 31 '22 at 13:13
  • im sorry. this is my first time asking here. i don't really know how to edit and I just found out this comment. I'm so so sorry. didn't mean it – NURUL IZZATI BINTI ISMAIL STUD May 31 '22 at 13:20
  • thanks for the help @Tomerikoo. I manage to get the output using the return function. sorry again for my lack of knowledge to use this website. – NURUL IZZATI BINTI ISMAIL STUD May 31 '22 at 13:24
  • No problem at all. There must be a first time... To avoid this in the future, take some time to go over the [tour], read about [ask] and about providing a [mre]. You can also browse the different [help] articles and head over to [meta] to read about community guidelines. Good luck! – Tomerikoo May 31 '22 at 13:26
  • thanks.. i will gladly do that in my free time later. should finish my assignment first. – NURUL IZZATI BINTI ISMAIL STUD May 31 '22 at 13:30

0 Answers0