carrancho / tomerater Goto Github PK
View Code? Open in Web Editor NEWProject for Codecademy Python course
Project for Codecademy Python course
get_average_rating
, watch out if the User
object has no ratings yet! If the user has no ratings and you call user.get_average_rating()
you will get a division by 0 error. The same things happens for get_average_rating
in class Book
. When testing your functions, always be careful about the edge cases!# Check email validity (@ exists and there is at least on . after it)
if "@" in email and "." in email[email.find("@")+1:]:
# Create a User instance
new_user = User(name, email)
Instead of checking the validity of the email in another class before creating an instance of the User
class, this type of validation checking can occur in the constructor of the User
class itself and throw an error if the constructor arguments are wrong. This saves you from having to do a similar if statement whenever you create a User
object and also fits better design wise in the User
class.
most_positive_user
, instead offor item in self.users:
# Get the average rating for the user instance
# calling it's get_average_rating method
avg = self.users[item].get_average_rating()
if avg >= rating_holder:
# Update the holders
rating_holder = avg
user_holder = self.users[item]
you can do it like so for improved readability:
for item in self.users.values():
# Get the average rating for the user instance
# calling it's get_average_rating method
avg = item.get_average_rating()
if avg >= rating_holder:
# Update the holders
rating_holder = avg
user_holder = item
Overall great job with your project! Most of my comments were nitpicks and suggestions to follow best coding practices and improve readability of your code, but you did an excellent job commenting everything!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.