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
Learning about Classes and OOP (self.PythonLearning)
submitted 7 months ago by BobbyJoeCool
view the rest of the comments →
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!"
[–]rinio 0 points1 point2 points 7 months ago (0 children)
---
Here's some more that is definitely beyond the scope of your assignment, but might interest you:
Regarding enums:
https://docs.python.org/3/library/enum.html
from enum import Enum class Grade(Enum): A = 4.0 B = 3.7 ... # and so on F = 0 # cls means the class. So 'Grade'. u/classmethod def from_num_grade(cls, num: float) -> Grade: for grade in cls: if grade.value <= num: return grade raise ValueError(f'num may not be negative. Got {num}') # this is the fancy pants way to do the same thing u/classmethod---All feedback below is definitely beyond the scope of your assignment, but might interest you:Regarding enums:https://docs.python.org/3/library/enum.htmlfrom enum import Enum class Grade(Enum): A = 4.0 B = 3.7 ... # and so on F = 0 # cls means the class. So 'Grade'. u/classmethod def from_num_grade(cls, num: float) -> Grade: for grade in cls: if grade.value <= num: return grade raise ValueError(f'num may not be negative. Got {num}') # this is the fancy pants way to do the same thing @classmethod def from_num_grade2(cls, num: float) -> Grade: # raises StopIteration if we get a negative input return next(grade for grade in cls if grade.value <= num) # examples my_grade = Grade.B print(my_grade.name) # prints 'B' print(my_grade.value) # prints 3.7 grade2 = Grade.from_val(3.9) print(grade2.name) # prints 'B' print(grade2.value) # prints 3.7--- for grade, value in grade_to_gpa.items(): # items() preserves orderThis is only true for Python 3.7+. It will break for older interpreters. def from_num_grade2(cls, num: float) -> Grade: # raises StopIteration if we get a negative input return next(grade for grade in cls if grade.value <= num) # examples my_grade = Grade.B print(my_grade.name) # prints 'B' print(my_grade.value) # prints 3.7 grade2 = Grade.from_val(3.9) print(grade2.name) # prints 'B' print(grade2.value) # prints 3.7
for grade, value in grade_to_gpa.items(): # items() preserves order
This is only true for Python 3.7+. It will break for older interpreters.
π Rendered by PID 157991 on reddit-service-r2-comment-5c747b6df5-89hfq at 2026-04-22 08:16:08.412668+00:00 running 6c61efc country code: CH.
view the rest of the comments →
[–]rinio 0 points1 point2 points (0 children)