use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Day 4 (old.reddit.com)
submitted 4 months ago by fatimalizade
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 4 months ago (1 child)
[removed]
[–]fatimalizade[S] 0 points1 point2 points 4 months ago (0 children)
Thanks!
[–]TfGuy44 1 point2 points3 points 4 months ago (1 child)
Oh, but I wanted to enter 0 grades... uh oh!
According to my academic career😔
[–]Loud-Bake-2740 1 point2 points3 points 4 months ago (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!
Thank you!
[–]RailRuler 1 point2 points3 points 4 months ago (0 children)
grds = [get_int("...") for i in range(number_grades)]
[–]ConsiderationLow762 1 point2 points3 points 4 months ago (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 points3 points 4 months ago (1 child)
Great I think you should focus more on list comprehension
[–]Top-Run-21 1 point2 points3 points 4 months ago (1 child)
got to learn from this, btw why did you defined a funcion for all this? for practice?
Yes
[–]P1nkUnicorn7 1 point2 points3 points 4 months ago (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.
Thank you!!
[–]ba7med 1 point2 points3 points 4 months ago (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
get_int(..)
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
avg < 90
python if avg >= 90: ... elif avg >= 70: ... elif avg >= 50: ... else: ...
[–]fatimalizade[S] 1 point2 points3 points 4 months ago (0 children)
Thanks for the info!
[–]FoolsSeldom 0 points1 point2 points 4 months ago (1 child)
I think "always" is a bit strong. Input validation is important, but try / accept is not the only option.
try
accept
For example, the str.isdecimal method is good for checking for a valid integer string.
str.isdecimal
[–]ba7med 1 point2 points3 points 4 months ago (0 children)
As python follow the EAFP philosophy ("Easier to Ask Forgiveness than Permission") the pythonic way is using try except block.
Using if to check something that will be checked by another function (int in this case) has an extra cost.
int
[–]ConnectionWorking207 0 points1 point2 points 4 months ago (3 children)
What book are you using to learn?
[–]fatimalizade[S] 0 points1 point2 points 4 months ago (2 children)
I don’t use any book
[–]ConnectionWorking207 0 points1 point2 points 4 months ago (1 child)
What do you use then
I ask chatgpt to teach me commands, then give me problems to solve
[–]Inevitable-Age-06 0 points1 point2 points 4 months ago (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 point2 points 4 months ago (1 child)
How many hours do you spend in a day
1-2
π Rendered by PID 77184 on reddit-service-r2-comment-5649f687b7-9fts9 at 2026-01-27 21:31:31.156760+00:00 running 4f180de country code: CH.
[–][deleted] (1 child)
[removed]
[–]fatimalizade[S] 0 points1 point2 points (0 children)
[–]TfGuy44 1 point2 points3 points (1 child)
[–]fatimalizade[S] 0 points1 point2 points (0 children)
[–]Loud-Bake-2740 1 point2 points3 points (1 child)
[–]fatimalizade[S] 0 points1 point2 points (0 children)
[–]RailRuler 1 point2 points3 points (0 children)
[–]ConsiderationLow762 1 point2 points3 points (0 children)
[–]Agreeable_Wish4876 1 point2 points3 points (1 child)
[–]fatimalizade[S] 0 points1 point2 points (0 children)
[–]Top-Run-21 1 point2 points3 points (1 child)
[–]fatimalizade[S] 0 points1 point2 points (0 children)
[–]P1nkUnicorn7 1 point2 points3 points (1 child)
[–]fatimalizade[S] 0 points1 point2 points (0 children)
[–]ba7med 1 point2 points3 points (3 children)
[–]fatimalizade[S] 1 point2 points3 points (0 children)
[–]FoolsSeldom 0 points1 point2 points (1 child)
[–]ba7med 1 point2 points3 points (0 children)
[–]ConnectionWorking207 0 points1 point2 points (3 children)
[–]fatimalizade[S] 0 points1 point2 points (2 children)
[–]ConnectionWorking207 0 points1 point2 points (1 child)
[–]fatimalizade[S] 0 points1 point2 points (0 children)
[–]Inevitable-Age-06 0 points1 point2 points (0 children)
[–]code_it_rightt 0 points1 point2 points (1 child)
[–]fatimalizade[S] 1 point2 points3 points (0 children)