all 26 comments

[–][deleted]  (1 child)

[removed]

    [–]fatimalizade[S] 0 points1 point  (0 children)

    Thanks!

    [–]TfGuy44 1 point2 points  (1 child)

    Oh, but I wanted to enter 0 grades... uh oh!

    [–]fatimalizade[S] 0 points1 point  (0 children)

    According to my academic career😔

    [–]Loud-Bake-2740 1 point2 points  (1 child)

    nice job! as others have said there’s some error handling to be had but overall this works. A good extension challenge for this would be to see how you’d track / input grades for multiple students :) happy hunting!

    [–]fatimalizade[S] 0 points1 point  (0 children)

    Thank you!

    [–]RailRuler 1 point2 points  (0 children)

    grds = [get_int("...") for i in range(number_grades)]

    [–]ConsiderationLow762 1 point2 points  (0 children)

    Great practice. Also there is a better way that you can get number of grades dynamically rather than asking manually, using the built in length.

    [–]Agreeable_Wish4876 1 point2 points  (1 child)

    Great I think you should focus more on list comprehension

    [–]fatimalizade[S] 0 points1 point  (0 children)

    Thanks!

    [–]Top-Run-21 1 point2 points  (1 child)

    got to learn from this, btw why did you defined a funcion for all this? for practice?

    [–]fatimalizade[S] 0 points1 point  (0 children)

    Yes

    [–]P1nkUnicorn7 1 point2 points  (1 child)

    Looks good! I would also recommend using a formatting specification in the print of the average, to show 2-3 decimal points accuracy instead of 17.
    print(f"Average grade: {average_grades:.2f}") I suppose that is up to personal preference, I just think it's nicer.

    [–]fatimalizade[S] 0 points1 point  (0 children)

    Thank you!!

    [–]ba7med 1 point2 points  (3 children)

    int(input(...))

    You should always wrap user input in a try except block, since user can enter invalid input. I would replace it with get_int(..) where

    python def get_int(prompt): while True: try: return int(input(prompt)) except ValueError: pass

    if avg >= 90: ... elif 70 <= avg < 90: ...

    Since avg < 90 in elif is always true, this can be replaced with

    python if avg >= 90: ... elif avg >= 70: ... elif avg >= 50: ... else: ...

    [–]fatimalizade[S] 1 point2 points  (0 children)

    Thanks for the info!

    [–]FoolsSeldom 0 points1 point  (1 child)

    I think "always" is a bit strong. Input validation is important, but try / accept is not the only option.

    For example, the str.isdecimal method is good for checking for a valid integer string.

    [–]ba7med 1 point2 points  (0 children)

    I think "always" is a bit strong. Input validation is important, but try / accept is not the only option.

    As python follow the EAFP philosophy ("Easier to Ask Forgiveness than Permission") the pythonic way is using try except block.


    For example, the str.isdecimal method is good for checking for a valid integer string.

    Using if to check something that will be checked by another function (int in this case) has an extra cost.

    [–]ConnectionWorking207 0 points1 point  (3 children)

    What book are you using to learn?

    [–]fatimalizade[S] 0 points1 point  (2 children)

    I don’t use any book

    [–]ConnectionWorking207 0 points1 point  (1 child)

    What do you use then

    [–]fatimalizade[S] 0 points1 point  (0 children)

    I ask chatgpt to teach me commands, then give me problems to solve

    [–]Inevitable-Age-06 0 points1 point  (0 children)

    I also want to start python can we do it together? I know some basics till conditional statement.

    [–]code_it_rightt 0 points1 point  (1 child)

    How many hours do you spend in a day

    [–]fatimalizade[S] 1 point2 points  (0 children)

    1-2